Exercise
While + Counter
Objetive
Write a java program to display the numbers 1 to 10 on the screen using "while".
Example Code
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++;
}
}
}