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.
-
Create a class called
MyName. Define amainmethod (make sure you do so correctly). -
After
main, define a method calledfirstName()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");
}
-
Define another method called
lastName()that prints your last name to the screen. -
Inside of
main, call firstName() and lastName(). -
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 inmain. -
Add a
System.out.println();after the call to lastName(). -
Lastly, define a method called
fullName(). It will call firstName(), space(), and lastName(). -
Call fullName() from
main. Your full name should now print to the screen twice.
(Solution: MyName.java)