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!