public class Xxx {
public static int ss(int[]arr){
int count=0;
int temp;
int n=arr.length;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
if(arr[j]==i+1 && j!=i)
{
count++;
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
return count;
}
public static void main(String[] args) {
int [] arr=new int[]{1,5,2,4,3};
System.out.println(ss(arr));
}
}
题目详情