Exercise
Use of {0} and comments
Objetive
Write a java program to ask the user for three numbers and display their multiplication. The first line must be a comment with your name and surname. It MUST look as follows:
// Your Name and Surname
Enter the first number to multiply:
12
Enter the second number to multiply:
23
Enter the third number to multiply:
2
Example Code
// Importing the Scanner class to handle input from the user
import java.util.Scanner;
public class Program {
// Main method, entry point of the program
public static void main(String[] args) {
// Create a scanner object to read input from the user
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the first number
System.out.print("Enter the first number to multiply: ");
int number1 = scanner.nextInt();
// Prompt the user to enter the second number
System.out.print("Enter the second number to multiply: ");
int number2 = scanner.nextInt();
// Prompt the user to enter the third number
System.out.print("Enter the third number to multiply: ");
int number3 = scanner.nextInt();
// Calculate the result of the multiplication
int result = number1 * number2 * number3;
// Display the result using variable placeholders
System.out.printf("The result of multiplying %d, %d, and %d is: %d%n", number1, number2, number3, result);
// Close the scanner
scanner.close();
}
}