1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package testexo;
import java.util.Scanner;
public class test5 {
private int note[];
private boolean entier;
private int nb;
public test5(int x){
note=new int[x];
}
public int saisirUneNote(Scanner scanner) {
String saisie;
while (entier == false) {
try {
saisie = scanner.nextLine();
nb = Integer.parseInt(saisie);
return nb;
} catch (NumberFormatException ex) {
entier =false;
System.out.println("Its not a valid Integer");
}
}
return 0;
}
public void saisirNotes() {
Scanner scanner = new Scanner(System.in);
System.out.println("saisir les notes");
for(int i = 0; i < note.length; i++) {
note[i] =saisirUneNote(scanner);
}
}
private void affiche(){
for(int i = 0; i < note.length; i++) {
System.out.println("indice"+i+" note:"+note[i]);
}
}
public static void main(String[] args) {
test5 t5 = new test5(2);
t5.saisirNotes();
t5.affiche();
}
} |