Code Example
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter name: ");
String name = input.nextLine();
System.out.print("Enter points: ");
int points = input.nextInt();
System.out.println(name + " scored " + points + " points.");
}
}
Expected Output
Enter name: Mayur
Enter points: 42
Mayur scored 42 points.
Practice Steps
- Open the Java compiler and paste the code into Main.java.
- Run it and answer the terminal prompts.
- Add another method to format the final message.