dimanche 27 novembre 2016

While / Do-While is not working in an if statement [duplicate]

This question already has an answer here:

Can someone help me with this please? I have a problem where when the user inputs a "Yes" the code doesn't begin from the start. Code is listed below.

    System.out.println("Press 1 to search a flight. Press 2 to exit");
        int option = Keyboard.readInt();
        if (option==1){
            String anotherFlightResult=null;
            String anotherFlight=null;
            while(anotherFlight=="No"){
            System.out.print("\u000C");
            System.out.println("Enter flight number to search: \t");
            String search = Keyboard.readString();
            System.out.print("\u000C");
            for(p=0; p<20; p++){
                if((search).equals(plane[p][0])){
                    System.out.println("Information about flight: "+plane[p][0]);
                    System.out.println("----------------------------------");
                    System.out.println("Flight Number: "+plane[p][0]);
                    System.out.println("Air Line: "+plane[p][1]);
                    System.out.println("To: "+plane[p][2]);
                    System.out.println("From: "+plane[p][3]);
                    System.out.println("Departure Time: "+plane[p][4]);
                    System.out.println("Estimated Time: "+plane[p][5]);
                    System.out.println("Status: "+plane[p][6]);
                    System.out.println("Distance: "+plane[p][7]+"km");
                }
            }
            System.out.println("");
            System.out.println("Do you want to search another flight?");
            anotherFlight = Keyboard.readString();
            if (anotherFlight=="No"){System.out.println("No");}else if (anotherFlight=="Yes"){System.out.println("Yes");}
             }
        }
        if (option==2){ System.out.print("\u000C");
            System.out.println("Program will now stop");
            System.exit(0);
        }

Aucun commentaire:

Enregistrer un commentaire