Decode School

Java Program to print ODD numbers till N

Get input n and print n odd numbers.

Sample Input 1:


Sample Output 1:

1 3 5 7 9 11 13

Program or Solution


Program Explanation

Instruction(s) inside the for block{} are executed repeatedly till the second expression (i<=lim) is true.

Here i and j are initialized to 1 and i is incremented by 2 and j is incremented by 1.

for each iteration, instructions inside the for block are executed unless j becomes greater than n.

so value of i (1,3,5,7.....) (n odd numbers) in each iteration will be printed using system.out.println(0