Lesson 1.3 · Write it
Message board
A whole programPython or Java4 tests, 3 of them hidden
On a phone? Put the lines in order instead
A lift has a small screen for messages. Write a program that reads one line typed by the user and prints it under a heading, on the line below.
- The first line is always
Message:, with a capital M and a colon. - The second line is the typed line, exactly as it was typed, including any spaces at the start. Spaces at the end of a line are ignored.
- Print nothing else.
Your program is run several times, with a different line typed each time. Only what it prints is checked.
In Python, read the line with input(), with nothing between the brackets. In Java, the page starts you with a class, its main method and a Scanner called scanner: read the line with scanner.nextLine().
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 4 times: the example below, and 3 hidden ones that check the rules above. Only what it prints is checked.
the heading, then the typed line (rules 1 and 2)
You type
- typed: Back at 3pm
It prints
Message: Back at 3pm