Algorithm153 [Java Festival] 정답, 오답 여부를 표시하고 총점을 구하는 프로그램 import java.util.Scanner; public class 보너스4번 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("=== 채점하기 ==="); String ox = sc.next(); String[] ox1 = ox.split(""); int score = 0; int sum1 = 0; int sum2 = 0; for(int i = 0; i < ox1.length; i++) { if(ox1[i].equals("o")) { score++; sum1 += score; } else { score = 0; sum2 = 0; } } int result = sum1+sum.. 2023. 3. 13. [Java Festival] 2차원 배열을 왼쪽으로 90도 회전하여 출력 public class P_23번 { public static void main(String[] args) { int[][] array = new int[5][5]; int cnt = 1; for(int i = 0; i < array.length; i++) { for(int j = 0; j < array[i].length; j++) { array[i][j] = cnt++; } } for(int i = 0; i < array.length; i ++) { for(int j = 0; j < array[i].length; j++) { System.out.print(array[j][4-i]+" "); } System.out.println(); } //0.0 0.1 0.2 0.3 0.4 //4.0 3.0 2.0 1.. 2023. 3. 13. [Java Festival] 8자리 정수를 입력받아 정수의 합을 출력 import java.util.Random; import java.util.Scanner; public class d { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("정수 입력 : "); int num = sc.nextInt(); int result = num; int sum = 0; while(result > 0) { sum = sum + (result%10); result = (result/10); } System.out.println("합은 "+sum+"입니다."); } } 2023. 3. 13. [Java Festival] 알파벳의 빈도를 대소문자 구별없이 카운트하기 import java.util.Scanner; public class d { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] count = new int[26]; System.out.print("입력 >> "); String target = sc.nextLine(); target = target.toLowerCase(); target = target.replace(" ", ""); for(int i = 0; i < 26; i++) { count[i] = 0; } for(int i = 0; i < target.length(); i++) { count[target.charAt(i)-97]++; } for(i.. 2023. 3. 13. [Java Festival] N과 X의 정수를 입력받고 X보다 작은 수만 출력 import java.util.Scanner; public class d { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("N 입력 >> "); int n = sc.nextInt(); System.out.print("X 입력 >> "); int x = sc.nextInt(); String result = ""; for(int i = 0; i > "); int num = sc.nextInt(); if(num < x) { result += num+" "; } } System.out.println("결과.. 2023. 3. 13. [Java Festival] 문자열 형태의 2진수를 10진수로 변환 public class You_28번 { public static void main(String[] args) { //문자열 형태의 2진수를 입력받아 //10진수로 바꾸는 프로그램을 작성하시오. String str = "01001101"; int result = Integer.parseInt(str, 2); System.out.print(str+"(2) = "+result+"(10)"); } } 2진수 --> 10진수 Integer.parseInt(변수, 2) 2023. 3. 11. 이전 1 ··· 16 17 18 19 20 21 22 ··· 26 다음