Problème avec la méthode Scanner
Bonjour tous le monde,
Je suis entrain de réaliser un petit programme sur java dans lequel je dois utiliser la méthode scanner et les différentes méthodes. J'ai réussi à créer le programme, depuis que j'ai ajouter scanner . Je rencontre des problèmes. Pouvez-vous me dire où se situe mon erreur ? J'ai fais public static scanner aussi mais elle m'affiche une erreur.
Je vous remercie d'avance.
Cordialement.
Tuba uba
Code:
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
| import java.util.*;
public class magasin{
Scanner clavier = new Scanner(System.in);
public static void main(String[] args){
int [][] tableau;int jour, numero_magasin;double total_magasin, total_jour, sommeTotal;
tableau = new int[5][6];
System.out.println("Saisir le numero de magasin entre 0 et 4");
numero_magasin = clavier.nextInt();
System.out.println("Saisir le numero de jour entre 0 et 6");
jour = clavier.nextInt();
vente(tableau);
total_magasin = total_vente_magesin(numero_magasin,tableau);
total_jour = total_vente_jour(jour, tableau);
sommeTotal = total_somme_des_magasin(tableau);
System.out.println("La somme total réalisé par le magasin" + " " + numero_magasin + " " +total_magasin);
System.out.println("La somme total réalié par suivant le jour" + jour + " " + " dans la totalité des magasin " + total_jour);
System.out.println("La somme total réalisé par les magasins dans une semain " + sommeTotal);
}
public static void vente(int[][] tab){
Scanner clavier = new Scanner(System.in);
for(int i = 0; i<5;i++){
for(int j = 0; j<6;j++){
System.out.println("Saisir la valeur pour le magasin"+""+ i+1+"et le jour"+""+j+1);
tab[i][j] = clavier.nextInt();
}
}
}
public static double total_vente_magesin(int num_magasin,int [][] tab ){
double somme = 0;
for(int j = 0; j<6;j++){
somme = somme + tab[num_magasin][j];
}
// System.out.println(somme);
return somme;
}
public static double total_vente_jour(int num_jour, int[][] tab){
double somme_jour = 0;
for(int i1 = 0;i1<5;i1++){
somme_jour = somme_jour+tab[i1][num_jour];
}
return somme_jour;
}
public static double total_somme_des_magasin(int[][] tab){
double somme_total = 0;
for(int i = 0; i<5;i++){
for(int j = 0; j<6;j++){
somme_total = somme_total + tab[i][j];
}
}
return somme_total;
}
} |
Voici l'erreur :
Citation:
javac magasin.java
magasin.java:11: error: non-static variable clavier cannot be referenced from a static context
numero_magasin = clavier.nextInt();
^
magasin.java:13: error: non-static variable clavier cannot be referenced from a static context
jour = clavier.nextInt();
^
2 errors