的错误是“找不到符号变量b” 我想了解以及如何正确地写的语法做while循环 感谢。找不到符号变量
import java.util.*;
public class pract3ex10 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
do {
System.out.println("Enter a positive");
int n = s.nextInt();
int x = n;
int m = 0;
if (x < 0) {
System.out.println("Thank You!");
} else {
while (x > 0) {
x = x/10;
m++;
}
System.out.println("Number of digits in " + n + "= " + m);
}
} while (n > 0);
}
}
哪里是变量b的代码? – Ankit
您将需要[while和do-while语句](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html) – Smit
当我在Java7中编译代码时,我得到'n不能被解析为一个变量'并且看起来是正确的,因为'n'是在'do {..} while循环中定义的,所以它在'while'条件之外。也许尝试在循环之前声明'int n = -1'。 – Pshemo