반응형
package com.company;
import java.util.Arrays;
import java.util.Scanner;
public class Main { //console값 입력 후 최소값 print
private static Scanner scanner = new Scanner(System.in); //console search
public static void main(String[] args) {
int[] arrayInteger= readIntegers(8);
printArray(arrayInteger);
System.out.println("Min = "+findMin(arrayInteger));
}
private static int[] readIntegers(int capacity){ //capacity->array
int[] array = new int[capacity];
System.out.println("Enter "+capacity+"integer values.\r");
for(int i=0; i<array.length; i++){
array[i]=scanner.nextInt(); //int값console에 입력가능토록
}return array;
}
//print Input array
private static void printArray(int[]array){
for(int i=0; i<array.length; i++){
System.out.println("Element "+i+ " = "+array[i]);
}
}
//findMin
private static int findMin(int[] array){
int Min=Integer.MAX_VALUE;
for(int i=0; i<array.length;i++){ //큰순서대로
if(array[i]<Min) {
Min = array[i];
}
}
return Min; //
}
}
Output
D:\IT\JDK\jdk11.0.6_10\bin\java.exe "-javaagent:D:\IT\IDEA\IntelliJ IDEA Community Edition 2020.1\lib\idea_rt.jar=49992:D:\IT\IDEA\IntelliJ IDEA Community Edition 2020.1\bin" -Dfile.encoding=UTF-8 -classpath D:\IT\NewProject\MinElementChallenge\out\production\MinElementChallenge com.company.Main
Enter 8integer values.
34
5
23
2
1
3
5
6
Element 0 = 34
Element 1 = 5
Element 2 = 23
Element 3 = 2
Element 4 = 1
Element 5 = 3
Element 6 = 5
Element 7 = 6
Min = 1
Process finished with exit code 0
'JavaCode(review)' 카테고리의 다른 글
ArrayList 기본 - GroceryList -console입력추가/제거/검색 (0) | 2020.05.27 |
---|---|
ReverseArrayChallenge / (0) | 2020.05.20 |
ArrayChallenge/ console 입력 값/ 큰 순서대로 나열(descending) (0) | 2020.05.19 |
Array Average / console입력값들. (0) | 2020.05.18 |
Burger Price/ OOP ex/ (0) | 2020.05.18 |