Read user input from console using Scanner class
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Username: "); String username = scanner.nextLine(); System.out.print("Password: "); String password = scanner.nextLine(); System.out.print("What is 2 + 2: "); int result = scanner.nextInt(); if (username.equals("admin") && password.equals("secret") && result == 4) { System.out.println("Welcome"); } else { System.out.println("Invalid username or password!"); } } }