Java Program:

- To print Odd numbers between 0 to N

Example:

User Input: 8

Output: 1 3 5 6 7

import java.util.Scanner;
public class OddNumbers {
  public static void main(String []args) {
    int num;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter your last number : ");
    num = userInput.nextInt();

    System.out.print("Your odd numbers are :");
    for (int i=1; i<num; i++)
      if(i%2!=0)System.out.print(i+" ");
  }
}

Output:

  Enter your last number : 6
  Your odd numbers are : 1 3 5
Program
basic

You should know first :

Odd numbers: Numbers not perfectly divisible by 2

(number % 2 != 0)

So, we are using a for loop till the last number entered and check every value for odd

for(int i=0; i<LastValue; i++) {
  //Check every 'i' for odd, if odd then print
}
Concept

Coming Soon !

Quick
Tutorial

Quote

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.