I have written some code, that if the user's input doesn't match the correct input, it spits out "login failed". Somehow, the code also spits that out, when the given input is correct
package laptos;
import java.util.Scanner;
public class laptos {
public static void main(String[] args) {
String pass = "input"; // absolute password
String user = "laptos"; // absolute username
String passin; // user input for password
String userin; // user input for user
System.out.println("Login required..");
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("Username: ");
Scanner userInput;
userInput = new Scanner(System.in);
userin = userInput.nextLine();
// username done
System.out.println("Password:");
userInput = new Scanner(System.in);
passin = userInput.nextLine();
// password done#
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
if(passin == pass && userin == user) {
System.out.println("Successful");
}
else {
System.out.println("failed");
}
}
}
Aucun commentaire:
Enregistrer un commentaire