Print Even Numbers in Java: Explanation & Practice
Print even numbers in a range
Problem summary
Print all even numbers from 2 to 10, each on a new line.
Starter code
public class Main {
public static void main(String[] args) {
// Print even numbers from 2 to 10
}
}Expected output and test cases
- Even numbers 2-10
2 4 6 8 10
Hints
- Start at 2 and increment by 2 each time
- Or use modulus to check if number is even
- i += 2 increments by 2
Related Control Flow exercises
- Practice Leap Year Check in Java
- Practice Print Numbers 1-5 in Java
- Practice Multiplication Table in Java
Practice all Control Flow exercises · Run this idea in the Java compiler