0
Java code
import java.util.*; import java.util.Collections; import java.util.Set; import java.util.Scanner; import java.util.List; class students { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter number of students"); int n= sc.nextInt(); String[] str = new String[n]; System.out.println("Please enter array elements"); for (int i = 0; i <=n; i++) { str[i] = sc.nextLine(); } List<String> list = Arrays.asList(str); Set<String> s = new HashSet<String>(list); for (String freq : s ) { System.out.println(freq + "-->" + Collections.frequency(list, freq)); } } } I can u say wts wrng in this code????
4 RĂ©ponses
+ 2
You have space for n elements but you are trying to store n+1 elements.
+ 2
1st for loop.
It should be i < n.
0
which line??? i didnt understood
0
I don't find...but don't forget to close the Scanner with sc.close()