public class Main { public static void main(String args[]) { int x,n=10; if(n%2==0) { for(x=1; x<=n; x++) { if(x%2==0) { System.out.println(x); } } } else { for(x=1; x<=n; x++) { if(x%2!=0) { System.out.println(x); } } } } }
2
4
6
8
10
public class Main { public static void main(String args[]) { int x,n; n=Integer.parseInt(args[0]); if(n%2==0) { for(x=1; x<=n; x++) { if(x%2==0) { System.out.println(x); } } } else { for(x=1; x<=n; x++) { if(x%2!=0) { System.out.println(x); } } } } }
2
4
6
8
10
import java.util.*; public class Main { public static void main(String args[]) { int x,n; Scanner s=new Scanner(System.in); System.out.println("Enter n value: "); n=s.nextInt(); if(n%2==0) { for(x=1; x<=n; x++) { if(x%2==0) { System.out.println(x); } } } else { for(x=1; x<=n; x++) { if(x%2!=0) { System.out.println(x); } } } } }
Enter n value : 10
2
4
6
8
10