我已經創建了程序的基本結構,但無論我嘗試什麼,我都無法退出循環。打破我的while循環
另外我希望它顯示用戶將輸入的信息;從鍵盤到控制檯,一旦退出循環,但我不知道如何做到這一點。
import java.util.Scanner;
public class Requirement1 {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
String name, game, time, points;
int i = 0;
System.out.println("Please Enter Your Name");
name = scan.nextLine();
System.out.println("Players Name: " + name);
while (i < 100)
{
Scanner scan2 = new Scanner(System.in);
System.out.println("Please Enter a Game Name (If You Are Done type \"quit\")");
game = scan.nextLine();
System.out.println("Game: " + game);
Scanner scan3 = new Scanner (System.in);
System.out.println("Please Enter Your Score");
points = scan.nextLine();
System.out.println("Your Score: " + points);
Scanner scan4= new Scanner (System.in);
System.out.println("Please Enter the amount of time Spent Playing in Minutes");
time = scan.nextLine();
System.out.println("Time played: " + time);
}
}
你試圖做什麼來擺脫循環?我沒有看到任何這樣的嘗試。 –
你正在做(我<100),你在哪裏遞增我,以便它會增長每次循環運行?順便說一句我不認爲你希望你的while循環運行,直到我<100,你想要的東西是這樣的:while(scan.hasNextLine()) – krackmoe
要添加到@ SotiriosDelimanolis的評論。當'(i <100)'爲假時,循環會退出,但是'i'在循環內部不會發生變化! –