【发布时间】:2015-03-31 15:40:08
【问题描述】:
在用户告诉程序停止之前,我无法让开关不断循环。 当提示用户输入 N 循环时,它们应该被送回开关的顶部
char stop;
while(stop == 'N'){
switch(choice){
case 1:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
displacement = (Math.pow(time,4)) + 16;
System.out.println("Felix's displacement is equal to " + displacement + " meters");
System.out.println("Stop the application(Y/N)");
stop = input.findWithinHorizon(".",0).charAt(0);
break;
case 2:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
velocity = 4*(Math.pow(time,3));
System.out.println("Felix's velocity is equal to " + velocity + " m/s");
break;
case 3:
System.out.println("Enter the time in seconds:");
time = input.nextInt();
acceleration = 12*(Math.pow(time,2));
System.out.println("Felix's acceleration is equal to " + acceleration + " m/(s*s)");
break;
default:
System.out.println("Please select a choice");
}
}
}
【问题讨论】:
-
进入循环时stop的值是多少?它没有设置,因此它不会进入循环。选择发送到什么?您根本没有更新循环中的选择。
-
@StackFlowed:嗯,不仅如此 - 它不会编译......它不是绝对分配的。
-
除此之外,如果
choice从未改变过,switch内部循环的用途是什么,它将一次又一次地执行相同的情况
标签: java while-loop switch-statement