Sunday 16 August 2015

WAP in java to accept n from user and to display all even and odd nos from 1 up to n.

//Even and odd nos. from 1 up to given range

import java.util.Scanner;

class Range_evn_odd {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a no:");
int n=sc.nextInt();

if(n<1)
System.out.println("INVALID INPUT");
else
{
System.out.println("Even Nos:");
for(int i=2;i<=n;i=+2)
System.out.println(i);

System.out.println("Odd Nos:");
for(int i=1;i<=n;i=+2)
System.out.println(i);


}
}

}

No comments:

Post a Comment