write a program to print odd number from 1 to 20 using loop java
Answers
Answered by
2
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
Similar questions
Social Sciences,
6 days ago
Physics,
6 days ago
Hindi,
6 days ago
India Languages,
13 days ago
Physics,
13 days ago
Math,
8 months ago
Math,
8 months ago
English,
8 months ago