백준 1330(두 수 비교하기)

한장민·2022년 5월 11일
0
post-thumbnail

두 수를 입력받아서 비교하기
Scanner를 사용한 코드

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(A > B) {
			System.out.println(">");
		} else if(A < B) {
			System.out.println("<");
		} else {
			System.out.println("==");
		}
		
	}

}

BufferedReader를 사용한 코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str," ");
		
		int A = Integer.parseInt(st.nextToken());
		int B = Integer.parseInt(st.nextToken());
		
		if(A > B) {
			System.out.println(">");
		} else if(A < B) {
			System.out.println("<");
		} else {
			System.out.println("==");
		}

	}

}

BufferedReader 가 시간이 100ms, 메모리가 3000kb정도 적은 모습. BufferedReader와 StringTokenizer의 조합 외에도 다른 조합으로도 사용할 수 있다고 봤는데 아직 사용법을 잘 모른다. 다른 조합으로도 사용할 수 있게 공부하자.

profile
HAAN YJGB

0개의 댓글