lundi 20 novembre 2017

How do I make my Java code decide whether to do this or that? [duplicate]

This question already has an answer here:

I would like to know how I could say in Java like if the scanner detects a yes then do this then if not do something else. For instance, I want to say if you type "yes" to this statement then a print line will pop up saying something but if I type "no" then another print line will pop up instead of "yes" result.

    System.out.println("What are you're hobbies, " + name + '?');
    String hobby = scanner.nextLine();
    System.out.println("I like " + hobby + " too!");
    System.out.println("Let's go do it together!");
    String decision = scanner.nextLine();
    if(yes) { 
       String.out.println("Let's go!")
    }
    if(no) { 
       String.out.println("Okay, have a nice day then.")
    }

Aucun commentaire:

Enregistrer un commentaire