no image
자바 [Programmers] 1단계 - 자릿수 더하기
public class Solution { public int solution(int n) { int answer = 0; while(n > 0){ answer += n%10; n/=10; } return answer; } } 맨 뒷자리 1의 자리부터 구해주면 쉽게 풀 수 있다. 입력 : 123 1단계 answer + = n%10 => (3) n / = 10 => (12) 2단계 answer + = n%10 => (2)n /= 10 => (1) 3단계 answer += n%10 => (1) n / 10 => (0) answer == 3 + 2 + 1 => 6
2024.02.18
no image
자바 [Programmers] 1단계 - 평균 구하기
class Solution { public double solution(int[] arr) { double answer = 0; double sum=0; for(int i=0; i
2024.02.18
no image
자바 [Programmers] 1단계 - 문자열을 정수로 바꾸기 (Integer.parseInt())
class Solution { public int solution(String s) { return Integer.parseInt(s); } } 문자열을 Integer형으로 바꾸는 문제이다. Integer.paserInt() 내장함수를 사용하면 쉽게 풀 수 있다.
2024.02.18
no image
자바 [Programmers] 1단계 - 나머지가 1이 되는 수 찾기
class Solution { public int solution(int n) { int answer = 0; for(int i=1; i
2024.02.18
no image
자바 [Programmers] 1단계 - 짝수와 홀수
class Solution { public String solution(int num) { return (num % 2 == 0) ? "Even" : "Odd"; } } 아주 기초적인 문제..
2024.02.18
no image
자바 [Programmers] 1단계 - x만큼 간격이 있는 n개의 숫자
class Solution { public long[] solution(int x, int n) { long[] answer = new long[n]; for(int i=0; i
2024.02.18
no image
자바 [Programmers] 1단계 - 약수의 합
class Solution { public int solution(int n) { int answer = 0; for(int i=1; i
2024.02.18
no image
자바 [JAVA] - 백준 1259번
import java.util.*;public class Baek1259 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = ""; while(true){ boolean check = true; str = sc.next(); if(str.equals("0")){ break; } for(int i=0; i입력을 String 타입으로 받고, 팰린드롬수인지 확인을 위해 boolean 변수 추가0 입력시 종료입력받은 값의 절반만큼 비..
2024.02.14