尝试使用负数和 if else 语句终止程序。有谁看到这有什么问题吗谢谢。
import java.util.Scanner;
public class Assignment {
public static void main(String args[]){
int n;
int i=0;
System.out.print("Enter a Number:");
Scanner scanner = new Scanner(System.in);
n= scanner.nextInt();
int backUp = n;
if(n>0)
n=n/10;
i++;
else if(backUp = -1)
System.out.print("program terminated......");
System.exit(0);
System.out.println("Number of Digits in " +backUp +" is " +i);
}
}
最佳答案
首先,=
用于赋值。使用 ==
进行比较。
此外,如果您想运行多行代码,则需要在 if
和 else
语句之后使用 {}
。
关于java - 使用 if else 语句终止程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19266947/