这段代码没问题并且运行良好。
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");
}
并运行,我的输入扫描仪没有停止,为此,我没有得到任何结果。为什么会这样?
请给我一个带有描述的解决方案。先感谢您。