. Write an application that displays all even numbers from 2 to 100 inclusive, and that starts a new line after every multiple of 20 (20, 40, 60, and 80). Save the file as EvenNums.java.
public class EvenNums {
public void printAllEvenNumbers(){
for (int i = 2; i <= 100; i++){
if(i == 20 || i == 40 || i == 60 || i == 80){
System.out.println();
}
if(i % 2 == 0) {
System.out.print(i + " ");
}
}
}
}
Comments
Leave a comment