I'm new to programming and I was wondering why my code wasn't working. I'm learning from Java for Dummies and this is the Try It Out problem on page 173.
It's a simple program that asks for username and password input from a pop-up window. What's got me stuck is that the first 2 sets of usernames and passwords work.
However, the 3rd set, xyril + huchay, returns false for some reason. Is this a grouping problem?
Thanks in advance.
package com.Josuer;
import javax.swing.JOptionPane;
public class TryItOut5 {
public static void main(String[] args) {
String username = JOptionPane.showInputDialog("Username: ");
String password = JOptionPane.showInputDialog("Password:");
if (
username != null && password != null &&
(
(username.equals("bburd") && password.equals("swordfish")) ||
(username.equals("hritter") && password.equals("preakston")) ||
(username.equals("xyril") && password.equals("huchay"))
)
)
{
JOptionPane.showMessageDialog(null, "You're in.");
} else {
JOptionPane.showMessageDialog(null, "You're suspicious.");
}
}
}
Aucun commentaire:
Enregistrer un commentaire