Bonjour,

Si j'utilse Scanner 1 --> çà tourne
Si j'utilse Scanner 2 --> çà tourne

Sii j'utilse Scanner 1 puis Scanner 2 , Scanner 2 ne fonctionne plus

Une idée , merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 ajeter;
 
import java.util.Scanner; 
 
public class Scan {
    public static void main(String[] args) { 
 
    	  // SCANNER 1
 
                Scanner sc = new Scanner(System.in); 
 
                String s = ""; 
 
                while(s.compareTo("ok")!=0)
                {
                	s = sc.nextLine(); 
                	System.out.println(s); 
                }
 
                sc.close();
 
          // SCANNER 2
 
                Scanner scan = new Scanner(System.in);
 
                System.out.println("Entrez un nombre entier à incrémenter :");
 
                while(scan.hasNext()) {
                	// Est-ce un int ? On l'incrémente
                		if (scan.hasNextInt())
                		{
                			int nb = scan.nextInt();
                			System.out.println(nb + " +1 = " + ++nb);
                			} 
                			// Ce n'est pas un int, affichage d'un message d'erreur.
                		else
                		{
                			System.out.println(scan.next() + " n'est pas un nombre.");
                		}                               
                }
                scan.close();
 
 
    }
}