Write a method called processName that accepts a Scanner for the console as a parameter and prompts the user to enter a full name, then prints the name in reverse order (i.e., last name, first name). Here is an example dialogue with the user:
Please enter your full name: Sammy Jankis
Your name in reverse order is Jankis, Sammy
Program:
import java.util.Scanner;
public class Ch03Ex15
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
processName(keyboard);
}
public static void processName(Scanner keyboard)
{
System.out.print("Please enter your full name: ");
String fname = keyboard.next();
String lname = keyboard.next();
System.out.print("Your name in reverse order is " + lname + ", " + fname);
}
}
Output:
Please enter your full name: Sammy Jankis
Your name in reverse order is Jankis, Sammy