Question

In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class...

In JAVA

#3 Write a program named nameChanger.java. This program will only have a driver class with a main. This program will have the user enter a series of names(first and last), which will then be stored in a String array. You will then change the values of each of the names in the array, so that they are stored lastname, firstname, and then output the revised array.

Sample:

Enter a name (first and last): Tonya Pierce

Enter a name (first and last): Susan Johnson

Enter a name (first and last): Bob Villa

Pierce, Tonya

Johnson, Susan

Villa Bob

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class nameChanger {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("How many names: ");
        String[] names = new String[in.nextInt()];
        in.nextLine();
        for (int i = 0; i < names.length; i++) {
            System.out.print("Enter a name (first and last): ");
            names[i] = in.nextLine();
        }
        for (int i = 0; i < names.length; i++) {
            String[] words = names[i].split(" ");
            names[i] = words[1] + ", " + words[0];
        }
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i]);
        }
    }
}

How many names: 5 Enter a name (first and last): Tonya Pierce Enter a name (first and last): Susan Johnson Enter a name (firs

Add a comment
Know the answer?
Add Answer to:
In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class...
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 you code in a class named HighScores, in file named HighScores.java. Write a program that...

    Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look approximately like this: Enter the name for score #1: Suzy Enter the score for score #1: 600 Enter the name for score...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • 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 C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter...

    Write a C++ program that produces the following output: /* OUTPUT Enter your age: 21 Enter the last name: Lee Hello Tom Lee. You are 21 years old. Press any key */   Declare an array named: firstName The array is a c_string, i.e., it is a null-terminated character array. The size of the array is 10. Assign a first name to it when it is declared.   Declare an array named: lastName The array is a c_string, The size of the...

  • a) In Atom, create a new program file named greetByfullName.jsin your pl folder. b) Write a...

    a) In Atom, create a new program file named greetByfullName.jsin your pl folder. b) Write a function named greetByfullName that accepts two strings (firstName and lastName), and returns a cheery greeting. c) Test the function by prompting the user to enter their first name, and storing the name in a variable, and then prompting the user for their last name, and storing it in a second variable. This page says Enter your first name Susan Cancel OK This page says...

  • 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 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

  • 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;...

  • Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char...

    Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char firstName[100]; char lastName[100]; printf("Enter Your Full Name: \n"); scanf("%s %s", firstName, lastName); printf("First Name: %s\n", firstName); printf("Last Name: %s\n", lastName); return 0; }

  • Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

    Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings. Create a MATLAB script named namephone.m and place these lines of code at the beginning: name  = input('Enter your first and last name: ','s'); phone = input('Enter your area code and phone number: ','s'); Tasks Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep As you work...

  • 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//    } }

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