Sunday 16 August 2015

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

//Odd nos. from 1 up to given range

import java.util.Scanner;

class Range_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
{
for(int i=1;i<=n;i=+2)
System.out.println(i);
}
}

}

No comments:

Post a Comment