java.util.Scanner 간단한 어플리케이션

1299 단어 Scanner
import java.util.Scanner;
import java.io.*;
public class FileScannerTest{
    public static void main(String args[]){
//**************Scanner     

//1.public Scanner(InputStream source),  InputStream       
       
       Scanner myScanner1 = new Scanner(System.in);
       while(myScanner1.hasNextInt()){
           int i=myScanner1.nextInt();
           System.out.println(i);
       }
//2.public Scanner(File source)  throws FileNotFoundException ,   File      
       
        try{
          Scanner myScanner2 = new Scanner(new File("in.txt"));
          while(myScanner2.hasNextInt()){
             int i=myScanner2.nextInt();
             System.out.println(i);
          }
        }catch(FileNotFoundException e){
           System.out.println("      !");
        }
//3.public Scanner(String str),     String      
        
       Scanner myScanner3 = new Scanner(new String("1 2 3 4 a f f 4 56"));//        hasNextInt()  false
       while(myScanner3.hasNextInt()){
             int i=myScanner3.nextInt();
             System.out.println(i);
          }

    }
}

좋은 웹페이지 즐겨찾기