1
我無法讓開關不斷循環,直到用戶告訴程序停止。 當用戶提示放在一個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");
}
}
}
進入循環時停止的值是多少?它沒有設置,因此它不會進入循環。什麼是選擇發送給?你根本沒有更新你的循環中的選擇。 – StackFlowed 2015-03-31 15:42:32
@StackFlowed:好吧,不僅如此 - 它不會編譯......它沒有明確分配。 – 2015-03-31 15:43:11
除此之外,如果'choice'永遠不會改變,那麼循環內部的'switch'有什麼用處呢,它會一次又一次地執行相同的情況 – silentprogrammer 2015-03-31 15:44:55