2013-04-17 5 views
-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");  

    } 
} 
+2

의미 생각하십니까? –

+1

'for' 및'while' 루프에 대해 알고 있습니까? [-> while 문 및 do-while 문] (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html) 및 [for> for 문] (http : // docs .oracle.com/javase/tutorial/java/nutsandbolts/for.html) – Smit

+0

올바르게 형식을 지정하십시오. – NINCOMPOOP

답변

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("---------"); 
    } 
} 
+0

루프가 멈추지 않습니다. 루프를 멈추기위한 메커니즘이 필요합니다. – Smit

+0

더 큰 프로그램에서 itergrate 할 수 있다면 제대로 Thread에 놓아야합니다. –

관련 문제