- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Test4.java
More file actions
Latest commit
41 lines (38 loc) · 988 Bytes
/
Copy pathArray_Test4.java
File metadata and controls
41 lines (38 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
importjava.util.*;
classArray_Test4{
publicstaticvoidmain(Stringar[]){
Scannersc=newScanner(System.in);
//5개의 정수값을 입력받아 배열에 넣고 최대값 구하기
System.out.println("5개의 정수 중에서 최대값 찾기♥");
inta[]=newint[5];
for (inti=0; i<a.length; i++) {
System.out.print("정수를 입력하세요. : ");
a[i]=sc.nextInt();
}
intmaxo=a[0];
for (inti=1; i<a.length; i++) {
if (maxo<a[i]) {
maxo=a[i];
}
}
System.out.println("최대값 : "+maxo);
//10개의 정수값을 입력받아 배열에 넣고 최대값, 최소값 구하기
System.out.println();
System.out.println("10개의 정수 중에서 최대값, 최소값 찾기♥");
intb[]=newint[10];
for (inti=0; i<b.length; i++) {
System.out.print("정수를 입력하세요. : ");
b[i]=sc.nextInt();
}
intmaxt=b[0], min=b[0];
for (inti=1; i<b.length; i++) {
if (maxt<b[i]) {
maxt=b[i];
}
elseif (min>b[i]) {
min=b[i];
}
}
System.out.println("최대값 : "+maxt+", 최소값 : "+min);
}
}