Java exercises on a certain site. A memo of the program that inputs the integer n as the standard input, then inputs n arbitrary numerical values and outputs the maximum value from them.
import java.util.Scanner;
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //Enter the integer n
      int num = sc.nextInt();
      int max = 0;
      int[] array = new int[num];
      //Enter an arbitrary value n times
      for(int i = 0; i < num; i++){
         array[i] = sc.nextInt();
         if(max < array[i]){
            max = array[i];
         }
      }
      System.out.println(max);
   }
}
Recommended Posts