uj5u.com熱心網友回復:
因為你if的判斷條件里有2個next(),建議先去看一下Scanner類的API再回來改你的代碼。uj5u.com熱心網友回復:
使用一個流就可以了,可以復用的,沒必要輸入一次創建一個流物件uj5u.com熱心網友回復:
還有你應該把輸入的資料用變數接收而不是在if里面再輸入兩次uj5u.com熱心網友回復:
System.out.println("?");
System.out.println("Y or N");
Scanner input = new Scanner(System.in);//建議去看一下Scanner的API手冊
String choose = input.nextLine();
if ("Y".equals(choose.toUpperCase())) {//使用equals的時候最好使用常量.equals,可以避免發生NullPointerException
System.out.println("name");
String name = input.nextLine();
System.out.println("hello," + name + "password");
String psd = input.nextLine();//盡量別用next(),如果遇到12 345這樣的,這個程式就結束了
if (psd.length() == 6) {
System.out.println("again");
if (psd.equals(input.nextLine())) {
System.out.println("success");
} else {
System.out.println("fail");
}
}
}
input.close();
uj5u.com熱心網友回復:
又一個入坑的孩子
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/123532.html
標籤:Java相關
