티스토리 뷰

import java.util.Scanner;

public class ScannerDemo {


  public static void main(String[] args) {
    String  s = "Hello World! 3+3.0 =6";
    Scanner sc = new Scanner(s);
    System.out.println(""+sc.hasNext() ); // 읽을게 있다면 true


    System.out.println(""+sc.nextLine() ); //한라인에 문장을 불러온다 Hello World! 3+3.0 =6


    System.out.println(""+sc.hasNext() ); //더이상 읽을게 없어서 false 로 리턴


    sc.close(); //Scanner 를 종료
  }
}

.next() 를 사용하게되면 Hello 를 갖고오게된다

.next() 를 3번사용하고 그뒤에 .hasNext() 를 사용해도 false 를 리턴한다