Source code
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("Enter the starting number: ");
int start=in.nextInt();
System.out.println("Enter the stoping number: ");
int stop=in.nextInt();
if(start>stop){
int temp=start;
start=stop;
stop=temp;
}
System.out.println("Even numbers between "+start+" and "+stop+" are: ");
for(int i=start;i<=stop;i++){
if(i%2==0){
System.out.print(i+" ");
}
}
}
}
Sample run
Comments
Leave a comment