0

String elements to array

Hi! I need some help. I have a task. There is one class and it has three parameter. String name Int birthYear Double average For example the name is John Smith Adams, the others are not important now. I solved one task to take out the first art of the name (John) but how can I take out the remaining two names without the first one in to an array? Thanks in advance!

19th Apr 2019, 6:27 PM
Tibor Tóth
Tibor Tóth - avatar
5 Answers
+ 8
Here I made this for you, check it out whether it helps you. :) https://code.sololearn.com/c5WWLS9s96x2/?ref=app
19th Apr 2019, 7:06 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
public class Program { public static void main(String[] args) { Info name = new Info("John Adams Smith"); String[] arr = name.getName().split(" "); String str1 = arr[0], str2 = arr[1], str3 = arr[2]; System.out.println(str1 + "\n" + str2 + "\n" + str3); } } class Info { private String name; Info(String name) { this.name = name; } String getName() { return name; } }
20th Apr 2019, 5:05 AM
blACk sh4d0w
blACk sh4d0w - avatar
0
Thanks! I'll try tomorrow! Is it not possibble to solve with String split? I have a working solution, but the tester program looks for the size of the array too.
19th Apr 2019, 8:20 PM
Tibor Tóth
Tibor Tóth - avatar