하루에 조금씩 알고리즘 문제 풀고 있는데 이번엔 비교적 쉬웠던거 같다.
그래서 생각을 해봤다 삼항연산자랑 if ~ else문을 사용 했을 때 뭐가 더 나은지
첫 번째 방법
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();
String result = ( a < b ? result = "<" : ( a > b ? result = ">" : ( a == b ? result = "==" : "" ) ) );
System.out.println(result);
}
}
두 번째 방법
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(-10000 <= a && -10000 <= b && 10000 >= a && 10000 >= b) {
if(a < b) {
System.out.println("<");
}else if( a > b) {
System.out.println(">");
}else {
System.out.println("==");
}
}
}
}
아직 잘 모르겠다. 그냥 느낌으로 삼항연사자로 쓰면 더 깔끔하게 보인다 정도..
이 생각은 찾아보면서 알아가야 겠다.