![](/img/trans.png)
[英]The second while loop is running endlessly can someone please explain why?
[英]Can someone please explain the structure of this while loop?
我需要知道为什么 sum=0 被初始化。 如果没有必要,我需要知道原因。 谢谢。
最初的问题是:给定输入正数 integer, output 每个数字在其自己的行上,从最右边的数字开始。 例如:如果输入为 935,则 output 为:5 3 9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int number, sum=0, r;
number = scnr.nextInt();
while(number!=0) {
r=number %10;
System.out.println(r + "");
number = number / 10;
}
/* Type your code here. */
}
sum = 0 不是必需的,因为您从不在程序中使用它,为什么要编写一个您永远不会使用的变量? 这就像买了一台电视机但从不使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.