package hi;
import java.util.Scanner;
class hi {
/**
* www.instanceofjava.com
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a binary number: ");
int binarynum = in.nextInt();
int binary = binarynum;
int decimal = 0;
int power = 0;
while (true) {
if (binary == 0) {
break;
} else {
int tmp = binary % 10;
decimal += tmp * Math.pow(2, power);
binary = binary / 10;
power++;
}
}
System.out.println("while is false");
System.out.println("Binary=" + binary + " Decimal=" + decimal);
}
}
我无法理解 while 循环是如何结束的。什么时候会while变成false?
繁星淼淼
相关分类