bonjour
j'ai essayé ce programme
en compilant j'ai erreur suivante aidez moi s'il vous plaît
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at exercice.Premier.main(Premier.java:5)
la ligne 5 est:
public static void main(String[]args)
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 import exercice.Clavier; public class Premier { public static void main(String[]args) { int i,n = 0,som; som=0; for(i=0;i<4;i++) { System.out.println("donnez un entier"); n=Clavier.lireInt(); som+=n; } System.out.println("Somme:"+som); } }
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 import java.io.* ; public class Clavier { public static String lireString () // lecture dune chaine { String ligne_lue = null ; try { InputStreamReader lecteur = new InputStreamReader (System.in) ; BufferedReader entree = new BufferedReader (lecteur) ; ligne_lue = entree.readLine() ; } catch (IOException err) { System.exit(0) ; } return ligne_lue ; } //Annexe D //La classe Clavier public static float lireFloat () // lecture dun float { float x=0 ; // valeur a lire try { String ligne_lue = lireString() ; x = Float.parseFloat(ligne_lue) ; } catch (NumberFormatException err) { System.out.println ("*** Erreur de donnee ***") ; System.exit(0) ; } return x ; } public static double lireDouble () // lecture dun double { double x=0 ; // valeur a lire try { String ligne_lue = lireString() ; x = Double.parseDouble(ligne_lue) ; } catch (NumberFormatException err) { System.out.println ("*** Erreur de donnee ***") ; System.exit(0) ; } return x ; } public static int lireInt () // lecture dun int { int n=0 ; // valeur a lire try { String ligne_lue = lireString() ; n = Integer.parseInt(ligne_lue) ; } catch (NumberFormatException err) { System.out.println ("*** Erreur de donnee ***") ; System.exit(0) ; } return n ; } // programme de test de la classe Clavier public static void main (String[] args) { System.out.println ("donnez un flottant") ; float x ; x = Clavier.lireFloat() ; System.out.println ("merci pour " + x) ; System.out.println ("donnez un entier") ; int n ; n = Clavier.lireInt() ; System.out.println ("merci pour " + n) ; } }
Partager