Exercise: Business Card

Ask the user for their name and address. Then, print the information with a top and bottom border. The border should be as long as the name or address line, whichever is longer.

For example (user input in green):
Enter your name:
Max Schwimmer
Enter your address:
Wohlwillstrasse 123
****************************
Name: Max Schwimmer
Address: Wohlwillstrasse 123
****************************
Another example where the line with the name is longer:
Enter your name:
Ludwig van Beethoven
Enter your address:
Shortstreet 4
**************************
Name: Ludwig van Beethoven
Address: Shortstreet 4
**************************

Hints 💡

To get the length of a string, use its length method. For example:
int nameLineLength = namePrefix.length() + name.length();

To print a string without a newline, use System.out.print instead of System.out.println. For example:
System.out.print("*");

To print just a line break and nothing else, use System.out.println().

Hand in instructions

  1. Make sure your program runs correctly.
  2. Hand in your program by uploading Main.java to Moodle.