Labs

We are going to write your name to the screen using methods. Each method has a specific job and a name relating to that job.

A complete solution is listed after all steps.

  1. Create a class called MyName. Define a main method (make sure you do so correctly).

  2. After main, define a method called firstName() that prints your first name to the screen, but without a newline character. It should look like

public static void firstName(){
    System.out.print("YOUR_FIRST_NAME");
}
  1. Define another method called lastName() that prints your last name to the screen.

  2. Inside of main, call firstName() and lastName().

  3. There is no space between the two names. Define a method called space() that prints a space character, " ", to the screen. Call it in the appropriate place in main.

  4. Add a System.out.println(); after the call to lastName().

  5. Lastly, define a method called fullName(). It will call firstName(), space(), and lastName().

  6. Call fullName() from main. Your full name should now print to the screen twice.

(Solution: MyName.java)


Prev -- Up