lundi 8 mai 2017

Loop or Repeat? [duplicate]

This question already has an answer here:

Is there a better way to loop or repeat these lines, or do I have to keep inserting them? Also, I want to know how to fix my "if" statements and my "==". The yes and the no will not register, so do I have to use a boolean?

import java.util.Scanner;

public class javaFirst {
    public static void main(String[] args){
        Scanner scanner1= new Scanner(System.in);
        Scanner scanner2= new Scanner(System.in);
        System.out.println("What do you think the color/theme to the prom should be this Fall?");
        String x = scanner1.nextLine();
        System.out.println("You think it should be " + x + "? Are you sure?");
        String y= scanner2.nextLine();
        scanner1.close();
        scanner2.close();if(y=="yes"){
        System.out.println("Ok, well then...");
        }
        else if(y=="no"){
            System.out.println("Ok, then what should the color be?");
            Scanner scanner3=new Scanner(System.in);
            String z= scanner3.nextLine();
            if(z=="yes"){
                System.out.println("Ok, well then...");
            }
            if(z=="no"){
                System.out.println("Then what should the color be?");
            }
            scanner3.close();
        }
        else{
            System.out.println("Please answer the question.");
        }

    }
}

Aucun commentaire:

Enregistrer un commentaire