I'm really fond of even numbers, you know? That's why I'll be letting you make another even number problem yet again. This time, you need to print from a range of two inputted numbers, n1 and n2 (inclusive), all the even numbers from n2 down to n1, in descending order.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter n1 number: ");
int n1 = in.nextInt();
System.out.print("Enter n2 number: ");
int n2 = in.nextInt();
for(int i = n2; i > 0; i--){
if(i%2 == 0){
System.out.print(i + ", ");
}
}
}
}
Comments
Leave a comment