-
가장 큰 숫자(메소드)코딩/java 2018. 11. 26. 12:43반응형
import java.util.Scanner;
public class Practice_29 {
public static void displayArray(int[] iArray) {
for (int i = 0; i < 10; i ++) {
System.out.print(iArray[i] + " ");
}
}
public static int findMax(int[] iArray) {
int max = -1;
for (int i = 0; i < 10; i++) {
if (max < iArray[i])
max = iArray[i];
}
return max;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num[] = new int[10];
for (int i = 0; i < 10; i++) {
System.out.print((i + 1) + "번째 숫자를 입력하세요: ");
num[i] = input.nextInt();
}
displayArray(num);
System.out.println("\n가장 큰 숫자는 " + findMax(num) + "입니다.");
input.close();
}
}
결과:
반응형'코딩 > java' 카테고리의 다른 글
랜덤한 숫자 중 가장 큰 숫자(메소드) (0) 2018.11.27 랜덤한 숫자 중 가장 큰 숫자 (0) 2018.11.26 숫자 별로 입력된 횟수 (0) 2018.11.26 5개의 숫자 출력 및 가장 큰 수(배열) (0) 2018.11.26 입력한 정수의 구구단(메소드 사용) (0) 2018.11.26