Skip to content

Commit f329667

Browse files
authored
Update Inversion_Count.java
1 parent e9e1977 commit f329667

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

GeeksForGeeks/Inversion_Count.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import java.util.Scanner;
22

3+
34
public class Inversion_Count {
4-
public static int[] input() {
5+
public static int[] input() { //This function is sued to take input from the user
56
System.out.println("Enter size of array: ");
67
Scanner sc = new Scanner(System.in);
78
int n = sc.nextInt();
89
int a[] = new int[n];
9-
for (int i = 0; i < n; i++) {
10+
for (int i = 0; i < n; i++) { //This forloop will help to store array
1011
a[i] = sc.nextInt();
1112
}
1213
return a;
1314

1415
}
15-
16+
//This is the main logic of the solution
17+
//The first loop will run till the length of array starting from 0
18+
//Second loop will run till length f array starting from (i+1);
1619
public static void inversecount(int a[]) {
1720
int count=0;
1821
for(int i=0;i<a.length;i++){
@@ -25,17 +28,16 @@ public static void inversecount(int a[]) {
2528
}
2629
}
2730
System.out.println("The Answer is: ");
28-
System.out.println(count);
31+
System.out.println(count);//The final answer is printed using this line
2932
}
3033
public static void main(String[] args) {
3134

3235
Scanner sc=new Scanner(System.in);
3336
System.out.println("Enter number of test cases you want to perform: ");
34-
int t = sc.nextInt();
37+
int t = sc.nextInt();//"t " stores the number of test cases you want to perform
3538
for (int p = 0; p < t; p++) {
3639
int a[] = input();
3740
inversecount(a);
38-
3941
}
4042
}
4143
}

0 commit comments

Comments
 (0)