Answer to Question #324723 in Java | JSP | JSF for Holly

Question #324723

Even Out (JAVA)

by CodeChum Admin

You know, I was lying when I said the last time that numbers associated with 3 are my favorite, because the one I actually like the most in the world are even numbers! But to make things harder for you, you have to pick the even numbers from a range of two given numbers. Ha!

Now, let's try this one more time! 


Instructions:

  1. Input two integers in one line, separated by a space. The first integer shall represent the starting point, and the other, the ending point.
  2. Print out all even numbers that are within the range of the starting and ending point (inclusive or including the ending point).

Input

A line containing two integers separated by a space.

5·10

Output

A line containing integers separated by a space.

6·8·10
1
Expert's answer
2022-04-09T17:55:47-0400
import java.util.Scanner;
class App {
    public static void main(String[] args) {
        Scanner keyBoard = new Scanner(System.in);
		int n1 = keyBoard.nextInt();
		int n2 = keyBoard.nextInt();
		for(int i=n1;i<=n2;i++){
		    if(i%2==0){
		        System.out.print(i+" ");     
		    }
		}
		keyBoard.close();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS