Question

Write a program that reads a persons first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is Maya Jones Tones, Maya import java . util·Scanner; public class SpaceReplace 4 public static void main (String [1 ares) f( Scanner scnr-new Scanner(System.in); String firstName; String lastName; Your solution goes here */ 10 12
1 1
Add a comment Improve this question Transcribed image text
Answer #1

Complete Program:

import java.util.Scanner; public class Space Replace { public static void main(String[] args) { Scanner scnr = new Scanner (S

Sample Output 1:

Maya Jones Jones, Maya

Sample Output 2:

Stan Li Li, Stan

CODE TO COPY:

import java.util.Scanner;

public class SpaceReplace {
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       String firstName;
       String lastName;

       firstName = scnr.next();
       lastName = scnr.next();

       System.out.println(lastName + ", " + firstName);
   }
}

Add a comment
Know the answer?
Add Answer to:
Write a program that reads a person's first and last names, separated by a space. Then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that reads a person's first and last names, separated by a space. Then...

    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. Example output if the input is: Maya Jones Jones, Maya import java.util.Scanner; public class SpaceReplace {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       String firstName;       String lastName; //answer goes here//    } }

  • read the code and comments, and fix the program by INSERTING the missing code in Java...

    read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....

  • Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput...

    Write a statement that outputs variable numTickets. End with a newline. import java.util.Scanner; public class VariableOutput ( public static void main (String D args) int numTickets; Scanner scnr new Scanner(System.in) scnr.nextint0:I/ Program will be tested with values: 15, 40. numTickets / Your solution goes here/

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a...

    Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print: 90, 92, 94, 95 Your code's output should end with the last element, without a subsequent comma, space, or newline. import java.util.Scanner; public class PrintWithComma {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       final int NUM_VALS = 4;       int[] hourlyTemp = new...

  • In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock"....

    In JAVA ACTIVITY 3.10.1: Rock-paper-scissors. Write a switch statement that checks nextChoice. If o print "Rock". If 1 print "Paper". If 2 print "Scissors'. For any other value, print "Unknown'. End with newline. 2. 4 1 import java.util.Scanner; 3 public class Roshambo public static void main(String [] args) { 5 Scanner scnr - new Scanner(System.in); 6 int nextChoice; 7 8 nextChoice - scnr.nextInt(); 9 10 /" Your solution goes here */ 11 12 13} CHALLENGE ACTIVITY 3.10.2: Switch statement to...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File;...

    JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 {    public static void main(String[] args) {        //scanner input from user    Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...

  • Write a program that prompts the user to enter a list of names. Each person's name...

    Write a program that prompts the user to enter a list of names. Each person's name is separated from the next by a semi-colon and a space (: and the names are entered lastName, firstName (i.e. separated by ',). Your program should then print out the names, one per line, with the first names first followed by the last names. A sample run of your program should look like Please enter your list of names: Epstein, Susan; St. John, Katherine;...

  • 6. Write a program that inputs the first name, middle initial (wirh period), and last name...

    6. Write a program that inputs the first name, middle initial (wirh period), and last name of a user and displays that person's n first name first, middle initial followed by a period, and last namelt hel will need the following variables: FirstName (a String) MiddleInitial (a String) LastName (a String) name with the

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT