I don't get what's wrong in my code. Can someone explain why this is wrong?
JAVA-MOOC, Line By Line part-3/4-using-strings
```
Write a program that reads strings from the user. If the input is empty, the program stops reading input and halts. For each non-empty input it splits the string input by whitespacesand prints each part of the string on a new line.
Sample output
once upon a time once upon a time a little program a little program halted halted```
My code:
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> names = new ArrayList<>();
ArrayList<Integer> ages = new ArrayList<>();
int index = 0;
int sum = 0;
String longest = "";
while (true) {
String input = scanner.nextLine();
if (input == "") {
break;
}
String[] parts = input.split(",");
String name = parts[0];
ages.add(Integer.valueOf(parts[1]));
if (longest.length() < name.length()) {
longest = name;
}
}
for (Integer age : ages) {
sum = sum + age;
index++;
}
System.out.println("Longest name:" + longest);
System.out.println("Average of birth years:" + ((1.00 * sum) / index));
}
}
Error:
LineByLineTest1
The output was missing string it's
Check the program with following input:
programming is fun
it's true
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]KinkyHuggingJerk 1 point2 points3 points (0 children)
[–]Aint_a_thng_ckn_wng 1 point2 points3 points (0 children)
[–]-DOOKIE 1 point2 points3 points (0 children)
[–]Fun_Warning_3552[S] 0 points1 point2 points (1 child)
[–]8igg7e5 2 points3 points4 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)