Skip to content
ExamSpine

Lesson 3.5 · Write it

Repeat message

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 message on the first line and a number on the second line, then prints the message that many times with line numbers starting from 1.

  1. Read the message (text) on the first line.
  2. Read the count (whole number) on the second line.
  3. Print each line as the line number, then a dot and a space, then the message.
  4. Line numbers start at 1 and go up to the count.

The count is always 1 or more. 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.

  • three lines numbered 1 to 3 (rules 3 and 4)

    You type

    1. typed: hello
    2. typed: 3

    It prints

    1. hello
    2. hello
    3. hello
  • one line (rule 4)

    You type

    1. typed: test
    2. typed: 1

    It prints

    1. test
  • two lines (rule 4)

    You type

    1. typed: bye
    2. typed: 2

    It prints

    1. bye
    2. bye
solution.pySolution.java