62,614
社区成员
发帖
与我相关
我的任务
分享
public class RotateArray{
public static void reverse(int[]array,int start,int end){
if(start>array.length||end>array.length){
System.out.println("the number out of Bounds");
return;
}
while(start<end){
int temp;
temp=array[start];
array[start]=array[end];
array[end]=temp;
start++;
end--;
}
}
public static void main (String[]args){
int[] a=new int[]{0,1,2,3,4,5,6,7,8,9,10};
int b=a.length;
RotateArray.reverse(a,0,5);
RotateArray.reverse(a,6,b-1);
RotateArray.reverse(a,0,b-1);
for(int i=0;i<b;i++){
System.out.print(a[i]+" ");
}
}
}