這段代碼是好的,運行良好。掃描不停止hasNextInt()
public static void main(String[] args) {
String [] keywords={"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto","if","int",
"long","register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while" };
Scanner sn = new Scanner (System.in);
if(Arrays.asList(keywords).contains(sn.next())) {
System.out.println("This is a KEYWORD");
}
但當我添加此
else if(sn.hasNextInt()){
System.out.println("This is an INTEGER");
}
和運行,我的輸入掃描儀沒有停止,而對於這一點,我沒有得到任何結果。 這是怎麼回事?
請給我一個解釋說明。先謝謝你。
你是什麼意思的「不停止」? –
不停止意思,它不給我任何輸出和仍然掃描輸入。 –