//BufferedReader is faster than scanner as it doesn't parse the text. Iterated over 1000 times, it saves 30 seconds in total. import java.io.BufferedReader; import java.io.InputStreamReader; class Even20To100 { public static void main(String[] args) throws java.io.IOException { for(int i = 0; i <= 100;i++){ if (i % 2 == 0){ System.out.print(i + " "); } } }}