mercredi 12 février 2020

Java How To control Flow tree

**When this code is ran it will continue to run even if you enter "y" in the If-Else Tree, how can I fix it so it does it's task which is to tell you how to fix a simple router issue **

import java.util.*;

public class WifiTest { public static void main(String [] args){

//Set up the global variables and such
String input;
Scanner scanner = new Scanner (System.in);

//Do We need to fix the connection?
System.out.println("Is your wifi bad? y/n: ");
input = scanner.nextLine();

//If ELSE TREE

if (input == "n"){
    System.out.println("There is no problem");    
}
else {
    System.out.println("Reset and reboot the Computer, did it fix it?: y/n");
    input = scanner.nextLine();
    if (input == "y") {
    System.out.println("Now it is fixed");
    }
    else {
    System.out.println("Reboot the Router and try again, did that fix the problem? y/n : ");
    input = scanner.nextLine();
        if (input == "y"){
    System.out.println("Now it is fixed");
    }
        else {
        System.out.println("Make sure the cables between the router a modem are firm, did that fix it? y/n: ");
        input = scanner.nextLine();
            if (input == "y"){
            System.out.println("Now it is fixed");
        }
            else{
        System.out.println("Move the router to a new location, did that fix the problem? y/n: ");
        input = scanner.nextLine();
                if (input == "y"){
            System.out.println("Now it is fixed");
        }
                else{
            System.out.print("Get a New Router");
        }
        }
    }
    }
}


}

}

Aucun commentaire:

Enregistrer un commentaire