Java

TOPIC 24 – FOR LOOPS, PART 2

 

LESSON WORK

 


QUESTION 1

Write the program that will output the following using a single FOR loop.

 

     1:10

     2:9

     3:8

     4:7

     5:6

     6:5

     7:4

     8:3

     9:2

     10:1

 

QUESTION 2 (NEW 2021)

 

Use independent nested for loops to output the pattern seen below.  The number of weeks should be determined by the user.

 

Week 1

  Day 1

  Day 2

  Day 3

  Day 4

  Day 5

  Day 6

  Day 7

Week 2

  Day 1

  Day 2

  Day 3

  Day 4

  Day 5

  Day 6

  Day 7

 

QUESTION 3 (CHANGED IN 2021)

Write the program that asks the user for a number of rows and outputs a pattern like below.  You might want to create a loop table for this.

 

Enter number of rows.
4

1
22
333

4444

 

Optional:
Are you able to change your program so that it does this instead:

 

4

33

222

1111

QUESTION 4

Write the program that asks the user for a number of rows and outputs a pattern like below.  Again, a loop table might be helpful here.

 

Enter number of rows.

5

 

**

  **

    **

      **

        **