如果Java中有条件,则程序控制不会脱离其他状态

时间:2018-08-29 16:12:34

标签: java loops if-statement java.util.scanner bluej

int pi_digits1=0;
int pi_digits2=0;

System.out.println("Would you like from starting to fixed no. or for a 
range:\n1.Fixed no\n2.Range");
byte choice = input.nextByte();

if(choice ==1){
    System.out.println("Enter the no. of digits after decimal within 1 million 
    of pi to see and play");
    pi_digits2=input.nextInt();
}
else if(choice ==2){
     System.out.println("Enter the smaller +ve no of range");
     pi_digits1=input.nextInt();
     System.out.println("Enter the larger +ve no of range");
     pi_digits2=input.nextInt();
     System.out.println("Check");
}
else{
    System.out.println("Wrong choice.Program terminated");
}

当选择为1时,循环工作正常。 但是对于选择2,在为pi_digits2输入之后,仍然要求 输入。

也正在打印支票,但是程序在输入循环中被敲击,因此 进一步的代码未执行。

Program executed in Bluej environment

0 个答案:

没有答案