j'ai écrit ce programme mais
en compilant j'ai erreur suivant
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method nextChar() is undefined for the type Scanner
aidez moi s'il vous plaît
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
47
48
49
50
51
52 package Textprg; import java.util.Scanner; public class Calculteur { public static void main (String[] args) { double firstnb; double secondnb; char operator; double value; System.out.println("Entrez expressions suc as 2+2 or 34.2*7.81"); System.out.println("To end ,enter a 0"); while(true) { System.out.println("Entrez votre premier Nb:"); Scanner sc=new Scanner(System.in); firstnb=sc.nextInt(); if(firstnb==0) break; System.out.println("operator"); Scanner sc1=new Scanner(System.in); operator=sc1.nextChar(); System.out.println("Entrez second Nb"); Scanner sc2=new Scanner(System.in); secondnb=sc2.nextInt(); switch(operator) { case'+': value=firstnb+secondnb; break; case'-': value=firstnb-secondnb; break; case'*': value=firstnb*secondnb; break; case'/': value=firstnb/secondnb; break; default: System.out.println("operator inconnue"+operator); continue; } System.out.println("vlaue is "+value); } System.out.println("Good Bye"); } }
Partager