File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import java .util .Scanner ;
22
3+
34public 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}
You can’t perform that action at this time.
0 commit comments