I am in a beginners java class and I have an assignment that is really difficult (for me). the assignment is to prompt the user to enter a person's full name in the order: first middle last.

Output will include: 
  the prompt 
  the original name
  the name in the form : last, first MI
  the entire name backwards
  the name in FML order with each part backwards

The output should use only one blank to separate the parts regardless of the
number of blanks originally entered in the name.

Example:
Enter a person's name: John Paul   Jones
John Paul Jones
Jones, John P.
senoJ luaP nhoJ
nhoJ luaP senoJ

Enter a person's name: John Smith
John Smith
Smith, John
htimS nhoJ

I don't know how to get this information to print out, I know i am most likely not using the correct methods etc. please help if you can !! Here is what I have...

public static void main(String [] args)
{

Scanner scan = new Scanner(System.in);


// variable initation
String input;
String firstName;
String middleName = "";
String lastName;


int lengthofInput;
int counter = 0;

System.out.println ("Enter a person's name: ");
input=scan.nextLine();

counter = 0;
while(input.charAt(counter)!=' ')
    counter++;

//First Name:

firstName = input.substring(0,counter);

input = input.substring(counter, input.length());
input = input.trim();

//Reset counter to 0 at the beginning of the next line

counter = 0;
while(input.charAt(counter)!=' ')
    counter++;

input = input.substring(counter, input.length());
input = input.trim();


//Middle Name:

if(input.lengthOf(' ')
{
counter = 0
while(input.charAt(counter)!=' ')
    counter++;

middleName = input.substring(0,counter);


input = input.substring(counter, input.length());
input = input.trim();

counter = 0;

input = input.substring(counter, input.length());
input = input.trim();
}


//Last name:

counter = 0
while(input.charAt(counter)!=' ')
    counter++;

lastName = input.substring(0,counter0;

input = input.substring(counter, input.length());
input = input.trim();



new StringBuffer(username).reverse() + "</tt>";//an idea i have don't know if it works


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

Thanks Alexa!

Edited 3 Years Ago by pyTony: fixed formatting

It must been your lucky day today :)
I have nothing to do so I typed that code for you

import java.util.Scanner;

class PrintMyName
{
	public static void main(String [] args)
	{
	
		Scanner scan = new Scanner(System.in);
		
		
		// variable initation
		String input;
		String firstName = null;
		String middleName = null;
		String lastName = null;
				
		int emptySpace = 0;
		int counter = 0;
		int firstEmpty = 0;
		int secondEmpty = 0;
		
		System.out.println ("Enter a person's name: ");
		input=scan.nextLine();
		input = input.trim(); // remove any empty characters before and after submited string
		
		System.out.println("\nName entered " + input + "\n");
		
		for(int i = 0; i < input.length(); i++)
		{
			if(input.charAt(i)== ' ')
			{
				emptySpace++;
				if(emptySpace == 1)
				{
					firstEmpty = i;
				}
				else if(emptySpace == 2)
				{
					secondEmpty = i;
				}
				else
				{
					input = input.substring(0, i); // remove extra chcarcters after last name
				}
			}
		}
		
		if(emptySpace == 1)
		{
			firstName = input.substring(0, firstEmpty);
			lastName = input.substring(firstEmpty+1, input.length() );
			System.out.println(lastName + ", " + firstName);
			System.out.println(reverse(lastName) + " " + reverse(firstName) );
			System.out.println(reverse(firstName) + " " + reverse(lastName) );
		}
		else
		{
			firstName = input.substring(0, firstEmpty);
			middleName = input.substring(firstEmpty+1, secondEmpty);
			lastName = input.substring(secondEmpty+1, input.length() );
			System.out.println(lastName + ", " + firstName + " " + middleName.charAt(0) + ".");
			System.out.println(reverse(lastName) + " " + reverse(firstName) + " " + reverse(middleName) );
			System.out.println(reverse(firstName) + " " + reverse(middleName) + " " + reverse(lastName) );
		}
	}
	
	public static String reverse(String str)
	{
		StringBuilder reverseStr = new StringBuilder(str);
		reverseStr.reverse();
		return reverseStr.toString();
	}	
}
This question has already been answered. Start a new discussion instead.