public void timer(){
myTimer.schedule(new TimerTask() {
int day=0;
String choose=null;
public void run() {
scan.nextLine(); // ***
do{
System.out.println("------- Day "+day+++" -----------------");
System.out.println("Status after organizing shelf");
shelf.printShelf();
shelf.addADay();
System.out.println("Continue? (y/n)");
choose = scan.nextLine(); //***
}while(choose.equals("y")||choose.equals("Y"));
System.exit(0);
}
},0,500);
}
ตรงที่เราทำเครื่องหมาย*** เอาไว้ scan.nextLine(); ตัวแรกเราไม่ได้ตั้งใจใส่เอาไว้ แต่ถ้าไม่ใส่ choose = scan.nextLine(); มันไม่ยอมทำงานไม่ยอมรับข้อความ ทำให้หลุดออกจาก loop โดยไม่ได้scan อะไรเลยอะงง
ใครเก่งจาวา ถามหน่อย
myTimer.schedule(new TimerTask() {
int day=0;
String choose=null;
public void run() {
scan.nextLine(); // ***
do{
System.out.println("------- Day "+day+++" -----------------");
System.out.println("Status after organizing shelf");
shelf.printShelf();
shelf.addADay();
System.out.println("Continue? (y/n)");
choose = scan.nextLine(); //***
}while(choose.equals("y")||choose.equals("Y"));
System.exit(0);
}
},0,500);
}
ตรงที่เราทำเครื่องหมาย*** เอาไว้ scan.nextLine(); ตัวแรกเราไม่ได้ตั้งใจใส่เอาไว้ แต่ถ้าไม่ใส่ choose = scan.nextLine(); มันไม่ยอมทำงานไม่ยอมรับข้อความ ทำให้หลุดออกจาก loop โดยไม่ได้scan อะไรเลยอะงง