Bonsoir j'aimerais faire un test de saisie d'un caractère, pour lire au clavier j'utilise une class Lire.
voici mon bout de script
pouquoi à la ligne if , j'ai une erreur de compilation ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 .... char choix; System.println("tapez la touche E ou la touche F"); choix = Lire.c(); if (choix == E) //eclipse m'indique E can't ge resolved { .... }
voici la class Lire
quelle est l'erreur que j'ai commit ?
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225 import java.io.*; public class Lire { public static String S() // Lire un String { String tmp = ""; char C='\0'; try { while ((C=(char) System.in.read()) !='\n') { if (C != '\r') tmp = tmp+C; } } catch (IOException e) { System.out.println("Erreur de frappe"); System.exit(0); } return tmp; } // fin de S() public static byte b() // Lire un entier byte { byte x=0; try { x=Byte.parseByte(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static short s() // Lire un entier short { short x=0; try { x=Short.parseShort(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static int i() // Lire un entier { int x=0; try { x=Integer.parseInt(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static long l() // Lire un entier long { long x=0; try { x=Integer.parseInt(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static double d() // Lire un double { double x=0.0; try { x=Double.valueOf(S()).doubleValue(); }import java.io.*; public class Lire { public static String S() // Lire un String { String tmp = ""; char C='\0'; try { while ((C=(char) System.in.read()) !='\n') { if (C != '\r') tmp = tmp+C; } } catch (IOException e) { System.out.println("Erreur de frappe"); System.exit(0); } return tmp; } // fin de S() public static byte b() // Lire un entier byte { byte x=0; try { x=Byte.parseByte(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static short s() // Lire un entier short { short x=0; try { x=Short.parseShort(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static int i() // Lire un entier { int x=0; try { x=Integer.parseInt(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static long l() // Lire un entier long { long x=0; try { x=Integer.parseInt(S()); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static double d() // Lire un double { double x=0.0; try { x=Double.valueOf(S()).doubleValue(); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static float f() // Lire un float { float x=0.0f; try { x=Double.valueOf(S()).floatValue(); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static char c() // Lire un caractere { String tmp=S(); if (tmp.length()==0) return '\n'; else { return tmp.charAt(0); } } } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static float f() // Lire un float { float x=0.0f; try { x=Double.valueOf(S()).floatValue(); } catch (NumberFormatException e) { System.out.println("Format numérique incorrect"); System.exit(0); } return x ; } public static char c() // Lire un caractere { String tmp=S(); if (tmp.length()==0) return '\n'; else { return tmp.charAt(0); } } }
je vous remercie d'avance de vos réponse
Partager