我试图进行无限加法计算。当我编译这段代码时,我得到无法访问的语句,我认为它是由不同的语句级别引起的。
import java.util.Scanner;
public class infiAdd {
public static void main (String [] args ){
int a;
char ans;
int c=0;
Scanner input;
input=new Scanner(System.in);
Bag: for(;;) {
System.out.print("Please enter a number:");
a=input.nextInt();
Bag2:for(;;) {
System.out.println("Do you wnat to add more ?[y/n]");
ans=input.next().charAt(0);
while (!(ans=='y')) {
while(!(ans=='n')){
System.out.println("Please enter a valid answer!");
continue Bag2;
}
c=c+a;
System.out.println("The result is :"+c);
}}
c=a+c;
continue Bag;}
}
}
无法到达的声明是c=a+c;