Ask Question
20 September, 17:05

Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline.

+3
Answers (1)
  1. 20 September, 19:49
    0
    The program to this question as follows:

    Program:

    //defining package

    import java. util.*; / /import package for user input

    public class Name / /defining class Name

    {

    public static void main (String ar []) / /defining main method

    {

    String First_Name, Last_Name; / /defining variables

    Scanner obc = new Scanner (System. in); / /creating Scanner class object

    System. out. print ("Enter your full name: "); / /message

    First_Name = obc. next (); / /taking input

    Last_Name = obc. next (); / /taking input

    System. out. println (Last_Name + ", " + First_Name); / /print value

    }

    }

    Output:

    Enter your full name: data base

    base, data

    Explanation:

    The description of the above java program as follows:

    A package is imported for user input in the first line of the program, then a class is defined, that is "Name", in this class two string variable is declared, that is "First_Name and Last_Name". In the next step, a scanner class object is created, which is "obc", which is used to take user input in this variable that is declared above. Then a print function is used to print the user input values, in printing time the last name is printed first that is separated by a comma then print the value of first name.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers