I just started picking up Java and ran into a problem with this practice question. I am supposed to print the number of duplicated lines in an input. Any help would be appreciated!
Sample input:
test
test
TesT
Sample output:
2
Here is my attempt that did not work:
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int count=0;
while(scan.hasNext()) {
String s = scan.nextLine()+"\n";
String first=s.split("\n")[0];
for (int i=0;i<s.length();i++){
if(first==s.split("\n")[i])
count++;
}
}
System.out.println(count);
}
}