What I’m trying to do is transform something like this: "The Three Pigs" into an array like this:
Array[0]="The"
Array[1]="Three"
Array[2]="Pigs"
The string class doesn’t have a method for that and I cant figure out how to do it myself
The split doesn’t seem to work for my purpose. Example code:
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
GetNumber();
}
private static void GetNumber() {
System.out.println("Enter your words.");
Scanner S=new Scanner(System.in);
String O=S.next();
String[] A=O.split(" ");
for(int Y=0;A.length>Y;Y++){
System.out.println(A[Y]);
}
}
}
This code would output The if i put in The Little Pigs
EDIT:
If you want to let the user to enter a line of text rather than a single word, then use:
instead of: