Even Out
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:
Input two integers in one line, separated by a space. The first integer shall represent the starting point, and the other, the ending point.
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
package even;
import java.util.Scanner;
public class Even {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int first = scan.nextInt();
int second = scan.nextInt();
for(int i=first; i<=second; i++){
if(i%2==0){
System.out.print(" "+i);
}
}
}
}
Comments
Leave a comment