I need user input 3 names separated by space, for example:
Please enter 3 names: name1 name2 name3
then I want to store it to array with 3 string elements as those 3 names, How to do that, please suggest me some method of STRING in java since I’m often use C++, I’m not asking for code, thank you!
String array[] = new String[3];
System.out.print("Please enter 3 names: ");
Scanner in = new Scanner(System.in);
String input = in.nextLine();
//do domething
This is a perfect place for
String.split()