java之二分法递归显示数列

public class rui {

public static void displayArray(int[] arr, int low, int high){
if(low == high){
	System.out.print(arr[low]+" ");
	}
   else{
	displayArray(arr, low, (high+low)/2);
	displayArray(arr, (low+high)/2+1, high);
	}
}
  void main(String[] args){
       int[] a = {1,3,5,7,9,2,4,6,8};
       System.out.println("涂涂说数组元素有:");
       displayArray(a, 0, a.length-1);

}

 
  
 
  

运行结果:

涂涂说数组元素有:
1 3 5 7 9 2 4 6 8 

你可能感兴趣的:(学习交流)