본문 바로가기

JAVA170

[D1] 1933. 간단한 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(); for(int i = 1; i 2023. 11. 18.
[D1] 2068. 최대수 구하기 1, 2, 3이라는 숫자가 출력되어야 하는데 0, 1, 2로 출력되어 fail이 떴던 문제... import java.util.*; class Solution { public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int i = 1; i 2023. 11. 18.
[D1] 2027. 대각선 출력하기 import java.util.Scanner; import java.io.FileInputStream; class Solution { public static void main(String args[]) throws Exception { for(int i = 0; i < 5; i++) { for(int j = 0; j < 5 ; j++) { if (i == j) System.out.print("#"); else System.out.print("+"); } System.out.println(); } } } 위의 방법이 더 쉽지만 다른 방법으로도 구현해보았다. class D1_2027 { public static void main(String[] args) { String str = "+++++"; char.. 2023. 11. 18.
[D1] 1936. 1대1 가위바위보 A가 이기는 경우들만 처리하고 나머지 경우는 else로 묶어 B가 이긴 것으로 했다 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(); if (A== 1 && B == 3) { System.out.println("A"); } else if (A == 2 && B == 1) { System.out.println("A"); } else if (A == 3 && B == 2) { Sy.. 2023. 11. 18.
[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.