Java substrings

I'm in my AP Computer Science class and we're supposed to make a program where you input a name, first and last, and the program will pick the name apart and display the last name then first. Nobody in our class has gained any progress in the day and a half we've been working on it and our teacher isn't giving us any help. Can I get some hints?

import APCS.Keyboard;

class StringLab

{

publicstaticvoid main(String[]args)

{

//

// define characters here

//

String str1 ="";

//

// enter your name section

//

System.out.println("Enter your name:"+str1+"");

str1 = Keyboard.readString();

System.out.println("You entered:"+str1+"");

//

// substring section to reverse name

//

}

}

That's all I have so far.

[1515 byte] By [fr0st_m0nkeya] at [2007-10-3 8:19:44]
# 1
> Nobody in> our class has gained any progress in the day and a> half we've been working on itWell if you can learn to read the tutorial's I bet you will be the only A.
zadoka at 2007-7-15 3:25:17 > top of Java-index,Java Essentials,Java Programming...
# 2

well, assuming that they're typing their full name (first [space] last) into str1, you can check out the String.split();

method. That may do what you are looking for.

For example:

String userInput = "My Name is Earl.";

String[] splitResults = userInput.split(" ");

Output:

splitResults[0] = "My"

splitResults[1] = "Name"

splitResults[2] = "is"

splitResults[3] = "Earl."

Navy_Codera at 2007-7-15 3:25:17 > top of Java-index,Java Essentials,Java Programming...
# 3

Not sure of your exact requirement, but this should get your started.

public static void main(String[] args) throws Exception

{

String name = "Mike Brown";

String[] splitName = name.split( " " );

System.out.println( "The name is: " + splitName[1] + ", "

+ splitName[0] );

}

Norweeda at 2007-7-15 3:25:17 > top of Java-index,Java Essentials,Java Programming...
# 4
and have a look at the following page, it tells you what all the String class can do for you: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
Navy_Codera at 2007-7-15 3:25:17 > top of Java-index,Java Essentials,Java Programming...
# 5
Thank you everybody!
fr0st_m0nkeya at 2007-7-15 3:25:17 > top of Java-index,Java Essentials,Java Programming...