Skip to content
ExamSpine

Lesson 1.4 · Write it

Name tag

A whole programPython or Java4 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a program that reads a name typed by the user and prints a name tag on one line: Tag: @ with the name straight after the @.

  1. The line starts with Tag:: a capital T and a colon, then one space, then @.
  2. The name comes straight after the @, with no space between them, exactly as it was typed.
  3. Everything is on one line. Print nothing else. Spaces at the end of a line are ignored.

Your program is run several times, with a different name typed each time. Only what it prints is checked.

In Python, read the name with input(). In Java, the page starts you with a class, its main method and a Scanner called scanner: read the name with scanner.nextLine(), build the whole line with +, and print it with one System.out.println.

You cannot use these in this question:

  • .format()
  • .join()

This question practises joining text with +, so build the whole line with + and print it once. The ways of building text listed here are not allowed.

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.

You cannot use these in this question:

  • .print()
  • .printf()
  • .format()
  • .join()

This question practises joining text with +, so build the whole line with + and print it once. The ways of building text listed here are not allowed.

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 tag, with the name straight after the @ (rules 1 to 3)

    You type

    1. typed: ada_s

    It prints

    Tag: @ada_s
solution.pySolution.java