Ejercicio
Tabla de multiplicar
Objetivo
Escriba un programa en java para pedir al usuario un número y mostrar su tabla de multiplicar, de la siguiente manera:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
...
5 x 10 = 50
Código de Ejemplo
// 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 a number
System.out.print("Please enter a number: ");
int number = scanner.nextInt();
// Display the multiplication table for the entered number
System.out.println("The multiplication table for " + number + " is:");
for (int i = 1; i <= 10; i++) {
int result = number * i;
System.out.println(number + " x " + i + " = " + result);
}
// Close the scanner
scanner.close();
}
}