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!
5 Answers
+ 8
Here I made this for you, check it out whether it helps you. :)
https://code.sololearn.com/c5WWLS9s96x2/?ref=app
+ 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;
}
}
+ 1
https://code.sololearn.com/W1s6oA7qiyyO/?ref=app
https://code.sololearn.com/W8n4T3TeYqrq/?ref=app
https://code.sololearn.com/W8c27PR31hA3/?ref=app
https://code.sololearn.com/Wkqv19iSrn4E/?ref=app
https://code.sololearn.com/cHg38Eo5wa4O/?ref=app
https://code.sololearn.com/WIY95yfLqOyy/?ref=app
https://code.sololearn.com/c3E6135qyLl9/?ref=app
https://code.sololearn.com/WUqa30C78l0L/?ref=app
https://code.sololearn.com/WJ2Ct5A32o9S/?ref=app
https://code.sololearn.com/WWFSU6qOphHk/?ref=app
https://code.sololearn.com/cvnD37C4ljcL/?ref=app
https://code.sololearn.com/caQ7J0ggY8o8/?ref=app
https://code.sololearn.com/cCaHBKyvtslI/?ref=app
https://code.sololearn.com/W4whyScOTd1A/?ref=app
https://code.sololearn.com/cyuqx6OV9kgG/?ref=app
https://code.sololearn.com/Wn0NIcHLf743/?ref=app
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.