my solution.
public static void main(String[] args) throws IOException {
for (int iterator = 1; iterator <= 100; iterator++)
// Check if the number is even
if (iterator % 2 == 0) {
// Print the even number
System.out.println(iterator);
}
}
The text of the exercise wants the numbers from 1 to 100 "Even"...
In discussione
Commenti (1)
- Popolari
- Nuovi
- Vecchi
Devi essere connesso per lasciare un commento
Anonymous #11516755
30 maggio 2024, 10:32
Good.
You could also simplify your code by iterating in the for loop only the even numbers.
for (int i = 2; i <= 100 ; i += 2){
System.out.println(i);
}
0