Lesson 1.5 · Write it
Repeat line
A whole programPython or Java4 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads one line typed by the user and prints it twice, on two lines.
- Each of the two lines is the typed line, exactly as it was typed.
- Print nothing else. Spaces at the end of a line are ignored.
Your program is run several times, with a different line typed each time. Only what it prints is checked.
In Python, save the line in a variable so you can print it twice. In Java, the page starts you with a class, its main method and a Scanner called scanner: read the line with scanner.nextLine() and save it in a String variable.
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 typed line, printed twice (rules 1 and 2)
You type
- typed: Hello again
It prints
Hello again Hello again