[프로그래머스] 자연수 뒤집어 배열로 만들기 class Solution { public int[] solution(long n) { String str = String.valueOf(n); int[] answer = new int[str.length()]; int count = 0; while (n > 0) { answer[count] = (int)(n % 10); n /= 10; count++; } return answer; } } Playground/자바문제집 2023.02.07
[프로그래머스] 자릿수 더하기 import java.util.*; public class Solution { public int solution(int n) { int answer = 0; while (n > 0) { answer += n % 10; n /= 10; } return answer; } } Playground/자바문제집 2023.02.07
[프로그래머스] 평균 구하기 import java.util.*; class Solution { public double solution(int[] arr) { return Arrays.stream(arr).average().orElse(0); } } Playground/자바문제집 2023.02.07
[프로그래머스] 약수의 합 class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i Playground/자바문제집 2023.02.07
[프로그래머스] 평행 import java.util.*; class Solution { public int solution(int[][] dots) { double[] line = new double[6]; int index = 0; for(int i = 0; i < 3; i++) { for(int j = i + 1; j < 4; j++) { double slope = (double)(dots[i][1] - dots[j][1]) / (double)(dots[i][0] - dots[j][0]); line[index] = slope; index++; } } for(int i = 0; i < 5 ; i++){ for(int j = i + 1; j < 6; j++) { if (line[i] == line[j]) return 1; }.. Playground/자바문제집 2023.02.07
[프로그래머스] 다항식 더하기 class Solution { public String solution(String polynomial) { int xCount = 0; int numCount = 0; for (String s : polynomial.split(" ")) { if (s.contains("x")) { xCount += s.equals("x") ? 1 : Integer.parseInt(s.replaceAll("x", "")); } else if (!s.equals("+")) { numCount += Integer.parseInt(s); } } return (xCount != 0 ? (xCount > 1 ? xCount + "x" : "x") : "") + (numCount != 0 ? (xCount != 0 ? " + " .. Playground/자바문제집 2023.02.07
[프로그래머스] OX퀴즈 class Solution { public String[] solution(String[] quiz) { String[] answer = new String[quiz.length]; for(int i = 0; i < answer.length; i++) { String[] arr = quiz[i].split(" "); if(arr[1].equals("+")) { if(Integer.parseInt(arr[0]) + Integer.parseInt(arr[2]) == Integer.parseInt(arr[4])) { answer[i] = "O"; } else { answer[i] = "X"; } } else { if(Integer.parseInt(arr[0]) - Integer.parseInt(arr[2]) .. Playground/자바문제집 2023.02.06
[프로그래머스] 저주의 숫자 3 class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i Playground/자바문제집 2023.02.06
[프로그래머스] 등수 매기기 import java.util.*; class Solution { public int[] solution(int[][] score) { List list = new ArrayList(); for(int[] i : score) { list.add((i[0] + i[1])); } list.sort(Collections.reverseOrder()); int[] answer = new int[score.length]; for(int i = 0; i < score.length; i++) { answer[i] = list.indexOf(score[i][0] + score[i][1]) + 1; } return answer; } } Playground/자바문제집 2023.02.06
[프로그래머스] 이진수 더하기 class Solution { public String solution(String bin1, String bin2) { int num1 = Integer.parseInt(bin1, 2); int num2 = Integer.parseInt(bin2, 2); int answer = num1 + num2; return Integer.toBinaryString(answer); } } Playground/자바문제집 2023.02.05