Exercise
Multiply using variables
Objetive
Write a java program to print the result of multiplying two numbers which will entered by the user.
Example Code
// Main class definition
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: ");
int number1 = scanner.nextInt();
// Prompt the user to enter the second number
System.out.print("Enter the second number: ");
int number2 = scanner.nextInt();
// Perform multiplication and store the result
int result = number1 * number2;
// Display the result on the screen
System.out.println("The result of multiplying the two numbers is: " + result);
// Close the scanner
scanner.close();
}
}