Write a program in java to print the odd numbers from 1 to 20.
Answers
Answered by
6
★ Code:
import java.util.Scanner;
class Even_Oddtill1{
public static void main (String args[]){
int i;
Scanner scan=new Scanner(System.in);
//create a scanner object for input
System.out.print("Print all odd number until:\n");
int num=scan.nextInt();//Reads input from user and stored in variable num
System.out.print("Odd number from 1 to "+num+" are: \n");
for(i=1; i<=num; i++){//loop for iterate from 1 to maximum
if(i%2==1)
System.out.print(i+"\n");
}
}
}
}
★Output:
Print all odd number until:
20
Odd number from i to 20 are
1
3
5
7
9
11
13
15
17
19
Answered by
1
Answer:
import java. util. * ;
class odd
{
public static void main ( string args [])
{
int a ;
system.out.println(" Odd Number from 1 to 20 :");
for ( a=1; a<=20; a++)
system.out.println (a);
}
}
Similar questions