Gadgets

Showing posts with label odd numbers. Show all posts
Showing posts with label odd numbers. Show all posts

Thursday, 3 December 2015

Print odd numbers in java

Print odd numbers in java
Any integer number is divisible by 2 and produces remainder is a fraction then that integer number is odd number.
import java.util.Scanner;
public class OddNumbers {
   public static void main(String[] arg){
        int number;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter any number :");
        number=sc.nextInt();
        System.out.println("Odd Numbers are");
        for(int i=0;i<=number;i++){
          if(i%2!=0){
              System.out.print(i+" ");
          }  
        }        
    } 
}
/*
Output:
Enter any number :
20
Odd Numbers are
1 3 5 7 9 11 13 15 17 19
*/