package javaapplication97;
import java.util.Scanner;
public class JavaApplication97 {
public static void main(String[] args) {
System.out.println("Enter a number: ");
Scanner s1 = new Scanner(System.in);
if (s1.hasNextInt())
System.out.println("This is an int");
}
}
答案 0 :(得分:0)
我认为你的意思是
import java.util.*;
public class test{
public static void main(String[] args) {
while(true){
System.out.println("Enter a number: ");
Scanner s1 = new Scanner(System.in);
if (s1.hasNextInt()){
System.out.println("This is an int");
}
else if(s1.nextLine().compareTo("stop")==0){
break;
}
else{
System.err.println("this is not an int");
}
System.out.println("---------");
}
}