1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
IrinaVladis [17]
3 years ago
6

Write a method called processName that accepts a Scanner for the console as a parameter and that prompts the user to enter his o

r her full name, then prints the name in reverse order (i.e., last name, first name). You may assume that only a first and last name will be given. You should read the entire line of input at once with the Scanner and then break it apart as necessary. Here is a sample dialogue with the user:
Output:Please enter your full name: Sammy JankisYour name in reverse order is Jankis, Sammywhat I have:public static void processName(Scanner in){System.out.print("Please enter your full name: ");String Name = in.nextLine();String lastName= in.subString(6,11);String firstName= in.subString(0,5);System.out.println("Your name in reverse order is " + lastName + ", " + firstName);}
Computers and Technology
1 answer:
ANEK [815]3 years ago
6 0

Answer:

Complete definition of method processName is as follows:

public static void processName(Scanner in){

   System.out.println("Please enter your full name: ");

   String Name = in.nextLine();

   String [] strings = Name.split(" ");

String firstName = strings[0];

String lastName = strings[1];

System.out.println("Your name in reverse order is " + lastName+ " "+ firstName);

}

Explanation:

Here subString method is not useful to break the string into first name and last name.

The better idea is to use the spilt(); function of string. split() function is used to split the given string into two halves depending on the delimiter passed as argument.

In the above method blank space (" ") is passed as delimiter. Thus split function stores the first half of string before blank space in strings array at location 0 and 1 respectively.

Sample program to implement above method:

import java.util.Scanner;

public class Main{

   public static void main(String [] args)

   {

       Scanner in = new Scanner(System.in);

       processName(in);

   }

   public static void processName(Scanner in){

   System.out.println("Please enter your full name: ");

   String Name = in.nextLine();

   String [] strings = Name.split(" ");

String firstName = strings[0];

String lastName = strings[1];

System.out.println("Your name in reverse order is " + lastName+ " "+ firstName);

   

}  

}

Sample output:

Please enter your full name:  

Jim hoppers

Your name in reverse order is hoppers Jim

You might be interested in
:P 80 points to spare so i guess its free!!!!!!
Naddik [55]

Answer:

Thank you! can i have brainliest please?

Explanation:

5 0
3 years ago
Read 2 more answers
Respecting yourself and others, educating yourself and connecting with others, and protecting yourself and others are all aspect
____ [38]

Answer: kind person

Explanation:

7 0
3 years ago
Read 2 more answers
Explain the difference between true north and magnetic north.
Furkat [3]
Magnetic north is the north a compass points in the direction of. True north, on the other hand, is north based on the earth's axis.
4 0
3 years ago
The background image does not affect any cell’s format or content. _______
Korvikt [17]
Hmmm...that is true 
Here a quizlet about if you need it!
https://quizlet.com/15207805/csci-241-flash-cards/
3 0
3 years ago
Which payment method typically charges the highest interest rates everfi
Valentin [98]
The answer is Payday loans.

Payday loans have the highest interest rates charged compared to credit cards, cashier's checks, and pre-paid cards. This type of loan is unsecured and is short -term. It is often called salary loan, payroll loan, or commonly known as cash advance loan.
8 0
3 years ago
Other questions:
  • _____________ is a service that provides access to hardware resources available over the Internet.
    11·1 answer
  • In internet terminology, what is the term, .com, called?
    12·2 answers
  • A program that coaches you at each step in the process is said to have a(n)
    12·2 answers
  • The function below takes two parameters: a string parameter: CSV_string and an integer index. This string parameter will hold a
    14·1 answer
  • Who are the four main antagonists in fnaf 1
    13·2 answers
  • What application service allows you to decouple your infrastructure using messaged based queues?
    10·1 answer
  • Facts and statistics collected together to be used for different purposes is
    14·1 answer
  • I came here for a answer so why did i get a pep talk
    7·2 answers
  • What does altgr mean on a keyboard.
    10·1 answer
  • Social media first became popular due to which development?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!