본문 바로가기

CodingTest/Programmers81

Lv.0 각도기 class Solution { public int solution(int angle) { int answer = angle==90 ? 2 : angle > 0 && angle 2022. 11. 21.
Lv.0 두 수의 합 class Solution { public int solution(int num1, int num2) { int answer = num1+num2; return answer; } } ' + ' 연산자로 두 수의 합 구하기 2022. 11. 20.
Lv.0 숫자 비교하기 class Solution { public int solution(int num1, int num2) { int answer = (num1==num2) ? 1:-1; return answer; } } 삼항연산자를 이용해서 구하기 (조건) ? 조건이 참인 경우 : 조건이 거짓인 경우 answer 변수에 num1과 num2가 서로 같으면 참이므로 1이 저장되고 같지 않으면 거짓이므로 -1이 저장 2022. 11. 20.
Lv.0 몫 구하기 class Solution { public int solution(int num1, int num2) { int answer = num1/num2; return answer; } } ' / ' 연산자를 이용해서 몫 구하기 2022. 11. 20.
Lv.0 두 수의 차 class Solution { public int solution(int num1, int num2) { int answer = num1-num2; return answer; } } ' - ' 연산자를 이용해서 두 수의 차를 구할 수 있다. 2022. 11. 20.
Lv.0 나머지 구하기 class Solution { public int solution(int num1, int num2) { int answer = num1%num2; return answer; } } 나머지를 구할 때 x / y : x를 y로 나눈 몫을 구할 때 사용하는 연산자 x % y : x를 y로 나누고 남은 나머지를 구할 때 사용하는 연산자 2022. 11. 20.
Lv.0 두 수의 곱 class Solution { public int solution(int num1, int num2) { int answer = num1*num2; return answer; } } 매개변수로 받은 num1과 num2를 리턴해줄 answer에 곱해서 넣어준다. 2022. 11. 20.
Lv.0 나이출력 public static int solution(int age) { int answer=0; answer = (2022-age)+1 return answer; } 우리는 나이를 1살부터 세서 2022기준-현재나이에 +1을 해준다. 2022. 11. 20.
Lv.0 삼각형의 완성02 public static int solution(int[] sides) { int answer = 0; int max = Math.max(sides[0], sides[1]); int min = Math.min(sides[0], sides[1]); answer += Math.abs((max-min)-max); answer += Math.abs((max+min)-(max+1)); return answer; } 배열의 큰 값과 작은 값을 Math클래스의 max,min함수를 통해 각각 저장해주고 1) max값이 긴변일 겨우 (max-min)-max 로 계산 ex) [11 7]일 경우 max는 11이 되고 제한사항 :가장 긴 변의 길이는 다른 두 변의 길이의 합보다 작아야 합니다. 참고하면 7+x 2022. 11. 20.
728x90
반응형