Zeeky Boogy Doog
Platinum Member
package mypackage1;
import javax.swing.*;
public class Password2
{
public static void main(String[] args) throws Exception
{
String password;
password = JOptionPane.showInputDialog("Enter Password");
System.out.println("The password is " + password);
if (password == "password")
{
System.out.println("You Win");
}
else
{
System.out.println("You Lose");
}
System.exit(0);
}
}
i'm in my first java class, and i'm having trouble with the problem, for some reason whenever i enter even the correct password, it goes to the else line, rather than the first if statement it should go to, i also tried assigning "password" to a variable and having if (password == input) where input = "password"
the teacher can't figgure it out either...
import javax.swing.*;
public class Password2
{
public static void main(String[] args) throws Exception
{
String password;
password = JOptionPane.showInputDialog("Enter Password");
System.out.println("The password is " + password);
if (password == "password")
{
System.out.println("You Win");
}
else
{
System.out.println("You Lose");
}
System.exit(0);
}
}
i'm in my first java class, and i'm having trouble with the problem, for some reason whenever i enter even the correct password, it goes to the else line, rather than the first if statement it should go to, i also tried assigning "password" to a variable and having if (password == input) where input = "password"
the teacher can't figgure it out either...