Printing even numbers with a skip condition

Report a typo

Write a program in Java that asks the user for a single input, an integer 'n'. Your task is to print all even integers up to 'n'. However, if the integer 10 is encountered while printing, your program should skip the number 10 and the five numbers that follow it. Then, continue printing the remaining even numbers until 'n'.

Sample Input 1:

20

Sample Output 1:

2 4 6 8 16 18 20

Sample Input 2:

11

Sample Output 2:

2 4 6 8
Write a program in Java 25
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Take the integer 'n' as input from user
int n = sc.nextInt();

// Loop from 1 to 'n' to print the numbers
for(int i = 1; i <= n; i++) {
// Include condition to check if 'i' is even
// If 'i' is 10, skip this number and the next five numbers


}

sc.close();
}
}

Create a free account to access the full topic