Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Intro2 {
- static String FirstName;
- static String LastName;
- /**
- * Sets the full name of the user.
- * @param fName - Users first name.
- * @param lName - Users last name.
- */
- static void setName(String fName, String lName) {
- FirstName = fName;
- LastName = lName;
- }
- /**
- * Gets the full name of the user.
- * @return - returns the full name entered by the user.
- */
- static String getName() {
- return String.format("%s %s%n", FirstName, LastName);
- }
- /**
- * Takes input from the user and stores them as first and last names.
- */
- static void InputName() {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter first name: ");
- String _fname = sc.next();
- System.out.print("Enter last name: ");
- String _lname = sc.next();
- setName(_fname, _lname);
- System.out.printf(getName());
- sc.close();
- }
- public static void main(String[] args) {
- InputName();
- System.out.println(FirstName);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement