Display even numbers from 5 to 5000 using the while loop ,for loop and do while loop
public class Main {
public static void main(String[] args) {
for (int i = 5; i < 5001; i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
int i = 5;
while (i < 5001) {
if (i % 2 == 0) {
System.out.println(i);
}
i++;
}
i = 5;
do {
if (i % 2 == 0) {
System.out.println(i);
}
i++;
} while (i < 5001);
}
}
Comments
Leave a comment