Write a program to print the first 20 odd numbers using while loop in a given range. Range will be given by user.Write a program to test the voter eligibility of any candidate. Age will be taken by user.

Answers 1

Answer:

Given: Range will be entered by user

Solution:

program to print 20 odd numbers using while loop

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

int num=sc.nextInt();

int i=1;

int inc=0;

while(i<=num)

{

    if(inc==20)

    {

    break;

    }

    if(i%2!=0)

    {

       int res=i;

       System.out.println(res);

       inc++;

    }

    i++;

}

}

}

This program will give all the odd numbers in the given range

Output:

20

1 3 5 7 9 11 13 15 17 19

If you know the answer add it here!

Can't find the answer?

Log in with Google

or

Forgot your password?

I don't have an account, and I want to Register

Choose a language and a region
How much to ban the user?
1 hour 1 day 100 years