I created a small project for myself in order to practice: the goal being to write precise things: and to obtain a message display, which allows "to access different things" however I block on a condition to recover the number written in console, via the scanner and to know if it is = the number which I declare in my int, in order to be able to display such or such message
I created 3 int :
int one = 1;
int two = 2;
int three = 3;
I would like with a condition of the style :
if(scanner.nextInt() == 1 && one == 1) {
System.out.println( You have access to the Administrator panel);
}
Retrieve the message sent to console (Eclipse Console) -> The number entered : If I write 1 : then I display a message, if I write 2 another message, and for 3 still another message.
After several attempts, I still haven't been able to succeed, being aware that it's something very basic despite the fact that I use the Scanner, I ask for your help in order to be able to understand my mistake I've been blocking for a few hours now I must admit that I've exhausted many "solutions".
My Entire code :
public static void main(String[] args) {
// Strictement inférieur à : <=
// Strictement supérieur à : >=
// Pas égal à : !=
try( Scanner scanner = new Scanner (System.in)) {
System.out.printf("Veuillez saisir votre login : ");
String login = scanner.nextLine();
System.out.println(" ");
System.out.printf("Veuillez saisir votre mot de passe : ");
String password = scanner.nextLine();
System.out.println(" ");
System.out.println("---| Vous êtes désormais connecté au panel |---");
System.out.println(" ");
System.out.println("1 - Accès Administrateur");
System.out.println("2 - Accès Modérateur");
System.out.println("3 - Accès Joueur");
System.out.println(" ");
int one = 1;
int two = scanner.nextInt(2);
int three = scanner.nextInt(3);
if(scanner.nextInt() == 1 && one == 1) {
System.out.println("Vous avez accès au panel Administrateur");
}
Aucun commentaire:
Enregistrer un commentaire