본문 바로가기

JAVA/SWEA12

[D1] 2071. 평균값 구하기 int가 아닌 float으로 sum을 선언하고 Math.round() 를 사용하면 되는구낭... Math.round(값); 메소드 사용시 값을 소수점 첫째 자리 까지 반올림 해줌 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 = sc.nextInt(); for(int i = 1; i 2023. 11. 18.
[D1] 2072. 홀수만 더하기 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 = sc.nextInt(); for(int i = 1; i 2023. 11. 18.
[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.