Wednesday, January 25, 2017


reverse the first n numbers of n array

public class ReversenNosOfArray{

public static void main(String args[]){

int arr[] = {1,2,3,4,5,6,7,8,9,10};

int i,n=5;

for(i=0;i < n--;++i)
{
    int temp = arr[i];
    arr[i]=arr[n];
    arr[n] = temp;

}

      for(i=0;i < 10;++i)
{
    System.out.println(arr[i]);
//5,4,3,2,1,6,7,8,9,10

}

}
}

No comments:

Post a Comment