728x90
반응형
SMALL
자가진단1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] arr = new char[100];
int[] arr2 = new int[26];
char ch;
int i;
for(i = 0; i < 100;i++){
ch = sc.next().charAt(0);
if((int)ch == 32) continue;
if((int)ch < 65 || (int)ch >90) break;
arr[i] = ch;
arr2[(int)ch - 65]++;
}
for(int j = 0; j < arr2.length; j++){
if(arr2[j] == 0) continue;
System.out.println(((char)(j + 65)) + " : " + arr2[j]);
}
}
}
자가진단2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[10];
int a;
while(true){
a = sc.nextInt();
if(a == 0) break;
arr[a/10]++;
}
for(int i = 0; i < arr.length; i++){
if(arr[i] == 0) continue;
System.out.println(i + " : " + arr[i]);
}
}
}
자가진단3
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[100];
arr[0] = 100;
arr[1] = sc.nextInt();
System.out.print(arr[0] + " ");
System.out.print(arr[1] + " ");
for(int i = 2; i < arr.length; i++){
arr[i] = arr[i-2] - arr[i-1];
System.out.print(arr[i] + " ");
if(arr[i]< 0) break;
}
}
}
자가진단4
public class Main {
public static void main(String[] args) {
int[][] arr = { {5, 8, 10, 6, 4},
{11, 20, 1, 13, 2},
{7, 9, 14, 22, 3}};
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
System.out.printf("%2d ",arr[i][j]);
}
System.out.println();
}
}
}
자가진단5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] fa = new int[2][4];
int[][] sa = new int[2][4];
System.out.println("first array");
for(int i = 0; i < fa.length; i++){
for(int j = 0; j < fa[i].length; j++){
fa[i][j] = sc.nextInt();
}
sc.nextLine();
}
System.out.println("second array");
for(int i = 0; i < sa.length; i++){
for(int j = 0; j < sa[i].length; j++){
sa[i][j] = sc.nextInt();
}
}
for(int i = 0; i < sa.length; i++){
for(int j = 0; j < sa[i].length; j++){
System.out.print((fa[i][j] * sa[i][j]) + " ");
}
System.out.println();
}
}
}
자가진단6
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[5][4];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = sc.nextInt();
}
}//end for
int sum = 0, count = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
sum += arr[i][j];
}
if(sum / 4 >= 80){
System.out.println("pass");
count++;
}
else System.out.println("fail");
sum = 0;
}
System.out.println("Successful : " + count);
}//end main
}
자가진단7
public class Main {
public static void main(String[] args) {
int[][] arr = new int[5][5];
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
if(i == 0 || j == 0) arr[i][j] = 1;
else arr[i][j] = arr[i-1][j] + arr[i][j-1];
}
}
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
728x90
반응형
LIST
'프로그래밍 > 자바' 카테고리의 다른 글
[자바] 정올 571 ~ 578 : 함수1 - 자가진단1 ~ 8 (1) | 2023.10.01 |
---|---|
[자바] 정올 160 ~ 169 : 배열2 - 형성평가1 ~ 10 (0) | 2023.09.30 |
[자바] 정올 150 ~ 159 : 배열1 - 형성평가 1 ~ 10 (0) | 2023.09.30 |
[자바] 정올 555 ~ 563 : 배열1 - 자가진단 1 ~ 9 (0) | 2023.09.27 |
[자바] 정올 140 ~ 149 : 반복제어문3 - 형성평가1 ~ 10 (0) | 2023.09.27 |