fork download
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Scanner;
  4.  
  5. public class SimpleLoginSystem {
  6. public static void main(String[] args) {
  7. // Create a map to store user credentials (username and password)
  8. Map<String, String> userCredentials = new HashMap<>();
  9. userCredentials.put("user1", "password1");
  10. userCredentials.put("user2", "password2");
  11.  
  12. // Create a Scanner object for user input
  13. Scanner scanner = new Scanner(System.in);
  14.  
  15. // Prompt the user for login credentials
  16. System.out.print("Enter username: ");
  17. String username = scanner.nextLine();
  18.  
  19. System.out.print("Enter password: ");
  20. String password = scanner.nextLine();
  21.  
  22. // Check if the entered username exists and the password matches
  23. if (userCredentials.containsKey(username) && userCredentials.get(username).equals(password)) {
  24. System.out.println("Login successful. Welcome, " + username + "!");
  25. } else {
  26. System.out.println("Login failed. Invalid username or password.");
  27. }
  28.  
  29. // Close the scanner
  30. scanner.close();
  31. }
  32. }
  33.  
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
��������������