我是新來的Java,我想知道是否有一種不同的方法,我可以使用,而不是has.nextInt(),因爲這種方法弄亂我的掃描儀。例如替代方法.hasNextInt?
do {
System.out.println("Please enter your full name: ");
memberName = input.nextLine();
if (input.hasNextInt()) {
System.out.println("Your name cannot contain a number");
input.next();
} else {
successful = true;
}
} while (successful == false);
控制檯
Create new member
Please enter your full name:
jack
jack
我必須輸入我的名字兩次運動之前在 我知道那裏有問題,有像這一點,但我已經受夠了任何存在的解決方案沒有運氣。由於
編輯
我想,以確保輸入不包含在所有的任何號碼,如果是的話那麼
System.out.print("Your name cannot contain any numbers");
發生
你有什麼期望'input.hasNextInt()'做什麼? –
你能提供一些你想接受的名字的例子嗎?你想接受'foo123'嗎?或者如果有人有兩個名字像傑克亞當史密斯那樣? – Pshemo
我只想接受只有喬博客,jon stevens的信件。我不想接受任何數字或foo123 @Pshemo –