I'm a new programmer and I'm having trouble with a Java if/else statement that uses Strings. Can someone help me find my problem? Here's the code of a part of the if statement:
System.out.println ("What planet are you traveling to?"); System.out.println ("Valid planets: Venus, Mars, Jupiter, Saturn, Uranus, Neptune"); Planet = keyboard.next(); //The Planet variable is a string System.out.println ("Your planet selection is " + Planet + "."); if (Planet == "Venus") //the code never uses this possibility, it always goes to the else statement { Weight = (Weight*0.78); System.out.println("Your weight on Venus is "+ Weight +"."); }
Then it goes to the else statement
Aucun commentaire:
Enregistrer un commentaire