Bonjour,
Mon code renvoie bien la valeur la plus grande mais l'exercice ne se valide pas. Quelle est mon erreur, s'il vous plait?
package fr.codegym.task.task07.task0701;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Maximum dans un tableau
*/
public class Solution {
public static void main(String[] args) throws Exception {
int[] tableau = initialiserTableau();
int max = max(tableau);
System.out.println(max);
}
public static int[] initialiserTableau() throws IOException {
// Create and populate the array
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
int[] tab = new int[20];
int nombre;
for (int i = 0; i < 20 ; i++) {
tab[i] = nombre = Integer.parseInt(lecteur.readLine());
}
return tab;
}
public static int max(int[] tableau) {
// Find the maximum
int max = 0;
for (int i = 0; i < 20 ; i++) {
if (max<tableau[i])
max = tableau[i];
}
return max;
}
}