![](https://i-blog.csdnimg.cn/blog_migrate/3c9ae7136456b72a7d2d88790a0582a2.png)
public static void main(String[] args) {
String s = "123456,987654,978654,967854,957896,945698,456987,1233211,565477";
String[] sArray = s.split(",");
int[] array = new int[sArray.length];
for (int i = 0; i < array.length; i++) {
array[i] = Integer.parseInt(sArray[i]);
}
int num = InversePairs(array);
System.out.println(1000000007 % num);//20
System.out.println( num%1000000007 );//21
}
public static int InversePairs(int[] array) {
int count = 0;
//判断当前与之后的每一个作比较。
for (int i = 0; i < array.length - 1; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[i] > array[j]) {
count++;
}
}
}
System.out.println("次数"+count); //
return count;
}
}