bonsoir, j'ai un petit problème avec mes programmes concernant les tableaux 2 dimensions.
Pour celui-ci, il vérifié s'il y a un nombre négatif ou = 0 dans le tableau et m'affiche "false" si c'est le cas. Or, il m'affiche correctement la réponse pour la première ligne, mais pas pour la seconde. Vous pouvez me dire qu'est-ce qui cloche, je galère depuis des heures avec un autre prog sur les tableaux 2D.
import java.util.Scanner;
public class positifs {
public static boolean check (int[][] tab) {
int i = 0; int j = 0;
boolean verif = true;
while ((i<2) && (verif==true)) {
while ((j<2) && (verif==true)) {
if ( tab[i][j] <= 0) {
verif = false;
}
j = j+1;
}
i = i+1;
}
return verif;
}
public static void main (String[] args) {
Scanner clavier = new Scanner (System.in);
int[][]tab = new int [2][2];
boolean verif = true;
System.out.println ("Valeurs à entrer : ");
for (int i=0; i<2; i++) {
for (int j=0; j<2; j++) {
tab[i][j] = clavier.nextInt();
}
}
verif = check (tab);
System.out.println ("Réponse : " +verif);
}
}
~
Merci.