Loops 我的while语句与我的BigDecimal不兼容
这个代码不起作用,我想知道为什么。问题似乎在while语句中,我似乎找不到问题所在。请在这里帮忙Loops 我的while语句与我的BigDecimal不兼容,loops,while-loop,bigdecimal,Loops,While Loop,Bigdecimal,这个代码不起作用,我想知道为什么。问题似乎在while语句中,我似乎找不到问题所在。请在这里帮忙 public static void main(String[] args) { //Creates the BigDecimal and scanner used BigDecimal answer = new BigDecimal("0"); Scanner scan = new Scanner(System.in); //While statemen
public static void main(String[] args) {
//Creates the BigDecimal and scanner used
BigDecimal answer = new BigDecimal("0");
Scanner scan = new Scanner(System.in);
//While statement to repeat if they dont answer 1 or 2
while (! answer.equals("1") && ! answer.equals("2")) {
//Asks user to input the number 1 or 2
System.out.print("Enter the number 1 or 2: ");
//Takes in users answer
answer = scan.nextBigDecimal();
}
//Uses printf to print what they typed in
System.out.printf("You entered the number %s.", answer);
scan.close();
}
您正在将BigDecimal对象与字符串“1”和“2”进行比较
这个怎么样
while (! answer.equals("1") && ! answer.equals("2")) {
请解释“不工作”是什么意思。它编译吗?它是否编译但抛出错误?错误消息是什么?它运行但没有给出正确的答案吗?它给出了什么答案?
while (! answer.equals(new BigDecimal("1")) && ! answer.equals(new BigDecimal("2"))) {