# 2. Write a program called ListOddNumbers that prints the below (there is a single space between each number). Printing odd numbers between 1 and 501 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 493. Write a program called NestedLoop that prints the below. Use a for nested loop. You need to use if nested loop. 122333444455555

Question
29 views

2. Write a program called ListOddNumbers that prints the below (there is a single space between each number).

Printing odd numbers between 1 and 50
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49

3. Write a program called NestedLoop that prints the below. Use a for nested loop. You need to use if nested loop.
1
22
333
4444
55555

check_circle

Step 1

Solution:

2.

The below program is written in Java language to display the odd number between 1 and 50.

The program has the following algorithm:

• The java class is created in the name of “ListOddNumbers”.
• In the main() method,
• The for loop executes until the number “50”. If condition satisfied,
• Then, check whether the number is odd. If yes,
• Display the odd numbers.
• End the for loop.

Step 2

Program:

//Define the class

public class ListOddNumbers

{

//Define the main() method

public static void main(String[] args)

{

//Display the message

System.out.println("Printing odd numbers between 1 and 50");

//Loop executes until the number "50"

for(int i=1;i<=50;i++)

{

//Check whether the number is odd

if(i % 2 != 0)

{

//Display the odd number with single space

System.out.print(i+" ");

}

}

//Display the empty line

System.out.println();

}

}

Step 3

Output:

Printing odd numbers between 1 and 50

1 3 5 7 9 11 13 15 17 19 2...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

### Computer Science 