Exercices Java sur un certain site. Un mémo du programme qui entre l'entier n comme entrée standard, puis entre n valeurs numériques arbitraires et en sort la valeur maximale.
import java.util.Scanner;
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //Entrez l'entier n
      int num = sc.nextInt();
      int max = 0;
      int[] array = new int[num];
      //Entrez n'importe quel nombre n fois
      for(int i = 0; i < num; i++){
         array[i] = sc.nextInt();
         if(max < array[i]){
            max = array[i];
         }
      }
      System.out.println(max);
   }
}
        Recommended Posts