728x90
반응형
SMALL
형성평가1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int val;
int[] count = new int[7];
for(int i = 0; i < 10; i++){
val = sc.nextInt();
count[val] += 1;
}
for(int i = 1; i < 7; i++) System.out.println(i + " : " + count[i]);
}
}
형성평가2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =1;
int[] people = new int[11];
int index;
while(true){
n = sc.nextInt();
if(n == 0)break;
index = n/10;
people[index]++;
}//end while
for(int i = people.length-1; i >= 0; i--){
if(people[i] != 0) System.out.println((i*10) + " : " + people[i] + " person");
}
}
}
형성평가3
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(), b = sc.nextInt();
int[] arr = new int[10];
arr[0] = a;arr[1] = b;
for(int i = 2; i < arr.length; i ++){
if(arr[i-2] + arr[i-1] < 10){
arr[i] = arr[i-2] + arr[i-1];
}else{
int n = arr[i-2] + arr[i-1];
n %= 10;
arr[i] = n;
}
}
for(int i = 0; i < arr.length; i ++) System.out.print(arr[i] + " ");
}
}
형성평가4
public class Main {
public static void main(String[] args) {
int[][] arr = {{3, 5, 9}, {2, 11, 5}, {8, 30, 10}, {22, 5, 1}};
int sum = 0;
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
System.out.print(arr[i][j] + " ");
sum += arr[i][j];
}
System.out.println();
}
System.out.println(sum);
}
}
형성평가5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[4][3];
for(int i = 0; i<arr.length; i++){
System.out.print((i+1)+"class? ");
for(int j = 0; j<arr[i].length; j++){
arr[i][j] = sc.nextInt();
}
}//end for
int sum = 0;
for(int i = 0; i<arr.length; i++){
System.out.print((i+1)+"class : ");
for(int j = 0; j<arr[i].length; j++){
sum+=arr[i][j];
}
System.out.println(sum);
sum = 0;
}//end for
}//end main
}
형성평가6
public class Main {
public static void main(String[] args) {
int[][] arr = new int[5][5];
arr[0][0] = 1; arr[0][2] = 1; arr[0][4] =1;
for(int i = 1; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
if(j-1 < 0) arr[i][j] = arr[i-1][j+1];
else if(j+1 > arr[i].length-1) arr[i][j] = arr[i-1][j-1];
else arr[i][j] = arr[i-1][j-1] + arr[i-1][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();
}
}
}
형성평가7
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] fa = new int[2][3];
int[][] sa = new int[2][3];
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();
}
}
}
형성평가8
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[4][2];
for(int i =0; i<4;i++){
for(int j = 0; j < 2; j++){
arr[i][j] = sc.nextInt();
}
}
int[] row = new int[4];
int[] col = new int[2];
int sum = 0;
for(int i =0; i<4;i++){
for(int j = 0; j < 2; j++) {
col[j] += arr[i][j];
row[i] += arr[i][j];
sum += arr[i][j];
}
}
for(int i : row) System.out.print((i/2) + " ");
System.out.println();
for(int i : col) System.out.print((i/4) + " ");
System.out.println();
System.out.println(sum/8);
}
}
형성평가9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[10][10];
for(int i = 0; i < 10; i++) arr[i][0] = 1;
for(int i = 1; i < 10; i++){
for(int j = 1; j < 10; j++){
arr[i][j] = arr[i-1][j-1] + arr[i-1][j];
}
}
int n = sc.nextInt();
for(int i = n-1; i >= 0; i--){
for(int j = 0; j < 10; j++){
if(arr[i][j] != 0) System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
형성평가10
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[][] arr = new char[3][5];
for(int i = 0; i < 3; i++){
for(int j = 0; j < 5; j++){
arr[i][j] = sc.next().charAt(0);
}
}
for(int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
System.out.print(Character.toLowerCase(arr[i][j]) + " ");
}
System.out.println();
}
}
}
728x90
반응형
LIST
'프로그래밍 > 자바' 카테고리의 다른 글
[자바] 정올 170 ~ 174 : 함수1 - 형성평가1 ~ 5 (0) | 2023.10.02 |
---|---|
[자바] 정올 571 ~ 578 : 함수1 - 자가진단1 ~ 8 (1) | 2023.10.01 |
[자바] 정올 564 ~ 570 : 배열2 - 자가진단1 ~ 7 (0) | 2023.09.30 |
[자바] 정올 150 ~ 159 : 배열1 - 형성평가 1 ~ 10 (0) | 2023.09.30 |
[자바] 정올 555 ~ 563 : 배열1 - 자가진단 1 ~ 9 (0) | 2023.09.27 |