Ejercicio
While + Contador
Objetivo
Cree un programa en java para mostrar los números del 1 al 10 en la pantalla, usando "while".
Código de Ejemplo
public class Program {
// Main entry point of the program
public static void main(String[] args) {
// Declare a counter variable starting from 1
int counter = 1;
// Start a while loop that will run as long as the counter is less than or equal to 10
while (counter <= 10) {
// Display the current value of counter
System.out.println(counter);
// Increment the counter by 1 after each iteration
counter++;
}
}
}