Solution: Get to Know the User
import java.util.Scanner;– allows the program to use the Scanner class for user input.public class Main– defines the classMain.public static void main(String[] args)– main method where the program starts.Scanner input = new Scanner(System.in);– creates a Scanner object to read input from the keyboard.System.out.print("Name: ");– displays a prompt asking for the user’s name.String name = input.next();– reads one word as the user’s name.System.out.print("Fav number: ");– prompts the user to enter a number.int number = input.nextInt();– reads an integer input.System.out.println("Cool, " + name + " - " + number + " is lucky!");– prints a combined message.
Solution: Get to Know the User
import java.util.Scanner;– allows the program to use the Scanner class for user input.public class Main– defines the classMain.public static void main(String[] args)– main method where the program starts.Scanner input = new Scanner(System.in);– creates a Scanner object to read input from the keyboard.System.out.print("Name: ");– displays a prompt asking for the user’s name.String name = input.next();– reads one word as the user’s name.System.out.print("Fav number: ");– prompts the user to enter a number.int number = input.nextInt();– reads an integer input.System.out.println("Cool, " + name + " - " + number + " is lucky!");– prints a combined message.