-
*** 클래스 명을 Main 으로 해야함. 그렇지 않다면 컴파일 에러가 난다.
1. 삼항 연산자를 이용한 솔루션
import java.util.Scanner; public class boj { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A , B ; A = sc.nextInt(); B = sc.nextInt(); String str = (A>B) ? ">" : ((A<B) ? "<" : "=="); System.out.println(str); } }
2. IF문을 이용한 솔루션
import java.util.Scanner; public class boj { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A , B ; A = sc.nextInt(); B = sc.nextInt(); if ( A == B ) System.out.println("=="); if ( A < B ) System.out.println("<"); if ( A > B ) System.out.println(">"); } }
차이는 미미했으나 시간상으로는 삼항연산자가 훨씬 좋았다.
'개발 > 알고리즘' 카테고리의 다른 글
알고리즘_ 자릿 수 더하기 (0) 2021.10.08 알고리즘_ 평행한 사각형에서 3개의 점과 나머지 한 점 (0) 2021.10.08 [백준/BOJ] JAVA_2588번 곱셉 과정 출력하기 (자바) (0) 2021.07.27 [백준/BOJ] JAVA_10430번 복합연산 출력하기 (자바) (0) 2021.07.27 [백준/BOJ] JAVA_10869번 사칙연산 출력하기 (자바) (0) 2021.07.27 댓글 (비로그인 댓글 허용하지 않습니다.)