Java program to display N odd number

Java program to display N odd number

Java program to print N odd number

Java program to display N odd number using for loop

Program:-

import java.util.Scanner;

class group{
public static void main(String angr[]){
Scanner num = new Scanner(System.in);
int n, i;
System.out.print("hey enter number:");
n=num.nextInt();
for(i=0; i< n; i++) { i=i+1; System.out.println(i); } } } Output:-

hey enter number:16
1
3
5
7
9
11
13
15


Java program to display N odd number using while loop

Program:-

import java.util.Scanner;

class group{
public static void main(String angr[]){
Scanner num = new Scanner(System.in);
int n, i;
System.out.print("hey enter number:");
n=num.nextInt();
i=0;
while(i< n) { i=i+1; System.out.println(i); i++; } } } Output:-

hey enter number:10
1
3
5
7
9

Java program to display N odd number using do while loop

Program:-

import java.util.Scanner;

class group{
public static void main(String angr[]){
Scanner num = new Scanner(System.in);
int n, i;
System.out.print("Hey enter number:");
n=num.nextInt();
i=0;
do
{
i=i+1;
System.out.println(i);
i++;
}while(i< n); } } Output:-

Hey enter number:5
1
3
5




Learn Java:-
Java codes

Java Programs:-
List of Java Programs

Leave reply

Add your comments here

Back to Top