코딩테스트/JAVA
[코딩테스트][JAVA] 두 수의 연산값 비교하기
팀센터
2024. 4. 27. 23:14
문제 : https://school.programmers.co.kr/learn/courses/30/lessons/181938
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
난이도 : LV0
내 풀이
class Solution {
public int solution(int a, int b) {
int answer = 0;
int num1 = Integer.parseInt("" + a + b);
int num2 = 2 * a * b;
// 'num1'과 'num2'를 비교하여 더 큰 값을 'answer'에 할당
answer = num1 > num2 ? num1 : num2;
return answer;
}
}
다른 사람 풀이
class Solution {
public int solution(int a, int b) {
return Math.max(Integer.parseInt(String.valueOf(a)+String.valueOf(b)),2*a*b);
}
}
Java Math : https://www.w3schools.com/java/java_math.asp