
Write a java propgram to find the list even and odd numbers between 1 and given input number.

import java.util.*;
public class EvenOddExample{
public static void main(String[]args){
String even=" ",odd=" ";
Scanner input=new Scanner(System.in);
System.out.println("Enter Number: ");
int n=input.nextInt();
for(int i=1;i<=n;i++){
if(i%2==0){
even+=i+" ";
}
else{
odd+=i+" ";
}
}
System.out.println("Odd Numbers between 1 and "+n+" are: "+odd);
System.out.println("Even Numbers between 1 and "+n+" are : "+even);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.