The program seems to work. It will replace duplicates with null. Unless it refers to itself, then it continues.
If I use Scanner.nextLine, it will end and display my results once I enter the 4th word, "Java". The only way I can enter more words is if I put something below it like a System.out.println(). Why is this? If I use Scanner.next() it works perfectly, but the checker won't take that. Seems like a bug.
package en.codegym.task.pro.task05.task0508;
import java.util.Scanner;
/*
Remove duplicate strings
*/
public class Solution {
public static String[] strings;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
strings = new String[6];
for (int i = 0; i < strings.length; i++) {
strings[i] = scanner.nextLine();
System.out.println();
}
for (int i = 0; i < 6; i++) {
for (int j = 1; j < strings.length; j++) {
if (strings[i] == null) {
continue;
}
if (strings[i] == strings[j]){
continue;
}
if (strings[i].equals(strings[j])) {
strings[i] = null;
strings[j] = null;
}
}
}
for (int i = 0; i < strings.length; i++) {
System.out.print(strings[i] + ", ");
}
}
}