Lesson 3.7 · Write it
Star rectangle
A whole programPython or Java6 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a number of rows and a number of columns, and prints a rectangle of * characters.
- Read the number of rows on the first line and the number of columns on the second line.
- Print that many rows, each containing that many
*characters. - Each row is on its own line. No spaces between the stars.
Both numbers are always whole numbers from 1 to 20. Your program is run several times. Only what it prints is checked.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
3 rows of 4 stars (rules 2 and 3)
You type
- typed: 3
- typed: 4
It prints
**** **** ****
one row of 5 stars (rule 2)
You type
- typed: 1
- typed: 5
It prints
*****
a square (rule 2)
You type
- typed: 2
- typed: 2
It prints
** **