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[10];
for(int i =0; i < 10; i++) arr[i] = sc.next().charAt(0);
for(int i = arr.length-1; i>=0; i--) System.out.print(arr[i] + " ");
}
}
형성평가2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
for(int i = 0; i < 5; i++) arr[i] = sc.nextInt();
System.out.println(arr[0]+arr[2]+arr[4]);
}
}
형성평가3
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 even = 0, odd = 0;
for (int i = 0; i < 10; i++) arr[i] = sc.nextInt();
for (int i = 0; i < arr.length; i++) {
if((i+1) % 2 == 0) even += arr[i];
else odd += arr[i];
}
System.out.println("odd : " + odd);
System.out.println("even : " + even);
}
}
형성평가4
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[100];
int temp, last_index = 0;
for(int i = 0; i < 100; i++){
temp = sc.nextInt();
if(temp == -1) break;
arr[i] = temp;
last_index++;
}
if(last_index > 2){
for(int i = last_index - 3; i < last_index; i++) System.out.print(arr[i] + " ");
}else{
for(int i = 0; i < last_index; i++) System.out.print(arr[i] + " ");
}
}
}
형성평가5
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double[] arr = new double[6];
for(int i = 0; i < 6; i++) arr[i] = sc.nextDouble();
double sum = 0;
for(int i = 0; i < 6; i++) sum += arr[i];
System.out.printf("%.1f", sum/6);
}
}
형성평가6
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] arr = {'J', 'U', 'N', 'G', 'O', 'L'};
int i;
char ch = sc.next().charAt(0);
boolean a = true;
for(i = 0; i < 6; i++){
if(arr[i] == ch){
a = false;
break;
}
}
if(a) System.out.println("none");
else System.out.println(i);
}
}
형성평가7
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[100];
int i, a;
for(i = 0; i < 100; i++){
a = sc.nextInt();
if(a == 999) break;
arr[i] = a;
}
int min = 999999;
int max = -999999;
for(int j = 0; j < i; j++){
min = arr[j] > min ? min : arr[j];
max = arr[j] < max ? max : arr[j];
}
System.out.println("max : " + max);
System.out.println("min : " + min);
}
}
형성평가8
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i,a, count = 0;
double sum = 0.0;
int[] arr= new int[100];
for(i = 0; i < 100; i++){
a = sc.nextInt();
if(a == 0) break;
arr[i] = a;
}
for(int j = 0; j < i; j++){
if(arr[j]%5 == 0) {
sum += arr[j];
count++;
}
}//end for
System.out.println("Multiples of 5 : " + count);
System.out.println("sum : " + (int)sum);
System.out.printf("avg : %.1f", sum/count);
}//end main
}
형성평가9
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[100];
int i,a;
for(i = 0; i < 100; i++){
a = sc.nextInt();
if(a == 0) break;
arr[i] = a;
}
System.out.println(i);
for(int j = 0; j < i; j++){
if(arr[j] % 2 == 0) System.out.print((arr[j]/2) + " ");
else System.out.print((arr[j]*2) + " ");
}
}
}
형성평가10
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Integer[] arr = new Integer[n];
for(int i = 0; i < n; i++) arr[i] = sc.nextInt();
Arrays.sort(arr, Collections.reverseOrder());
for(int i = 0; i < n; i++) System.out.println(arr[i]);
}
}
728x90
반응형
LIST
'프로그래밍 > 자바' 카테고리의 다른 글
[자바] 정올 160 ~ 169 : 배열2 - 형성평가1 ~ 10 (0) | 2023.09.30 |
---|---|
[자바] 정올 564 ~ 570 : 배열2 - 자가진단1 ~ 7 (0) | 2023.09.30 |
[자바] 정올 555 ~ 563 : 배열1 - 자가진단 1 ~ 9 (0) | 2023.09.27 |
[자바] 정올 140 ~ 149 : 반복제어문3 - 형성평가1 ~ 10 (0) | 2023.09.27 |
[자바] 정올 549 ~ 553 && 634 : 반복제어문3 - 자가진단 1 ~ 7 (0) | 2023.09.27 |