-4
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");    

    }
}
4

1 回答 1

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("---------");
    }
}
于 2013-04-17T16:10:15.297 回答