Ask Question
19 February, 23:38

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.

+1
Answers (1)
  1. 20 February, 02:17
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers