Subject:
CBSE BOARD XAuthor:
brielleCreated:
1 year agoAnswer:
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
Author:
deonmsop
Rate an answer:
1