본문 바로가기

JAVA/SWEA12

[D1] 2058. 자릿수 더하기 습관처럼 for을 쓰려다 while로 다시 작성했다 import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int sum = 0; while(n > 0) { sum += n % 10; n /= 10; } System.out.println(sum); } } 2023. 11. 18.
[D1] 2043. 서랍의 비밀번호 for문을 사용해서 풀어보려다가 계속 fail이 났던 문제... 이렇게 쉬운 방법이 있는데 for문에 꽂혀서 생각을 못했다 import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int P = sc.nextInt(); int K = sc.nextInt(); System.out.println(P-K+1); } } for을 사용해서 다시 풀어보았다! import java.util.Scanner; class D1_2043 { public static void mai.. 2023. 11. 18.
[D1] 2025. N줄덧셈 처음으로 바로 푼 문제! import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int sum = 0; for(int i = 1; i 2023. 11. 18.
[D1] 1938. 아주 간단한 계산기 nextInt가 바로 생각이 안 날 수가 있나? 공부한게 다 어디로 간 건지 ㅎㅎ... 내 공부 방법이 잘못됐었나 싶다 import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println(a + b); System.out.println(a - b); System.out.println(a * b); System.out.println(a / b); } } 2023. 11. 18.
[D1] 2047. 신문 헤드라인 알고 있는 함수인데도 이렇게 생각이 안 나다니... 반성😢 import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); str = str.toUpperCase(); System.out.println(str); } } 2023. 11. 18.
[D1] 2046. 스탬프 찍기 백준, 프로그래머스, SWEA 등 들은 건 있지만 직접 문제를 풀어본 건 부끄럽지만 오늘이 처음이다... 가장 쉬워보이는 스탬프 찍기부터 시작! import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T; T=sc.nextInt(); for(int test_case = 1; test_case 2023. 11. 18.