Ejercicio
Repetir hasta 0 (Usa Do while)
Objetivo
Cree un programa en java para pedir al usuario un número "x" y mostrar 10*x. Debe repetirse hasta que el usuario ingrese 0 (usando "do-while").
Código de Ejemplo
import java.util.Scanner; // Import Scanner class for input
public class Program {
// Main entry point of the program
public static void main(String[] args) {
// Create a scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Declare a variable to store the number entered by the user
int x;
// Start a do-while loop that will repeat until the user enters 0
do {
// Ask the user to input a number
System.out.print("Enter a number (0 to stop): ");
// Read the input from the user
x = scanner.nextInt();
// Display the result of 10 * x
if (x != 0) {
System.out.println("10 * " + x + " = " + (10 * x));
}
} while (x != 0); // The loop continues as long as x is not 0
// Close the scanner to free up resources
scanner.close();
}
}