Computer Science, asked by anasgazi8186, 13 days ago

write a program to print odd number from 1 to 20 using loop java​

Answers

Answered by naren96
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