본문 바로가기
Java 정리/Scanner

(JAVA) Scanner

by Kimuky 2024. 10. 5.

1) 간단한 사용방법

1. import를 통해 호출

import java.util.Scanner;

 

2. Scanner 객체 생성

//클래스 이름 = New 클래스();
Scanner sc = new Scanner(System.in); // Scanner 뒤 sc는 자유, 객체를 사용할 때 쓰는 것

 

3. short, int, long, float, boolean, 공백 기준, 개행 기준으로 입력 받는법

// short, int, long, float, boolean, 공백 기준, 개행 기준으로 입력 받는법

import java.util.Scanner;
public class App {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        short a = sc.nextShort();
        int b = sc.nextInt();
        long c = sc.nextLong();
        float d = sc.nextFloat();
        boolean g= sc.nextBoolean();
        
        String next = sc.next(); // 공백 기준
        String nextln = sc.nextLine(); //개행 기준
    }

}