I am trying to list all the content in a text file then calculate the number of each element by ignoring the first element in each row and sort it in descending order. I don't know how can i sort it.
The content of the text file :
1,2,8,4,5,6,7,7,
3,4,5,6,7,8,3,
5,6,7,8,9,9,
I want the expected result to like this :
Exam[1] : 2 8 4 5 6 7 7
count : 7
Exam[3] : 4 5 6 7 8
count : 5
Exam[5] : 6 7 8 9 9 3
count : 6
Sorted :
How can i sort count 7, count 6 and count 5 in descending order ?
I have tried using this sorting :
private static void sortInDescending(int[] num){
int n = num.length;
int temp = 0;
for(int i = 0; i < n; i++) {
for(int j = 1; j < (n-i); j++) {
temp = num[j-1];
num[j-1] = num[j];
num[j] = temp;
}
}
}
But this sort is to sort each element in each row in descending order.
This is my coding that i done so far :
Scanner scanner = new Scanner(new File("test.txt"));
int row = 0;
int count = 0;
while(scanner.hasNextLine()) {
String currentline = scanner.nextLine();
row++;
String[] items = currentline.split(",");
int[] intitems = new int[items.length];
int i = 0;
for(i = 0; i < items.length; i++) {
intitems[i] = Integer.parseInt(items[i]);
if(i == 0) {
System.out.print("Exam[" +intitems[i]+ "] ");
} else {
System.out.print(intitems[i]+ " ");
count++;
}
}
System.out.println("\nCount " +count);
count = 0;
}