Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

C Books Guide and List
C++ Books Guide and List
Best Java Books

0 votes
871 views
sir i am able to print the array in reverse order by using below code but i am not able to reverse the given array.
public class Reverse
{
    public static void main(String args[])
    {
        int a[]={1,2,3,4,5,6,7,8,9};
        for(int i=a.length-1;i>=0;i--)
        {
            System.out.println(a[i]);
        }
    }
}
asked by (15.3k points) 18 45 77

1 Answer

+1 vote
 
Best answer

well try ..that is absolutely correct but we have to do some more  work... 

public class ReverseArray{
public static void main(String ar[]){
int array[]={5,4,1,7,9,6};
for(int i=array.length-1,j=0;i>array.length/2-1;i--,j++){
int temp=array[j];
array[j]=array[i];
array[i]=temp;
}
for(int k=0;k<array.length;k++)
System.out.print(array[k]+"  ");
}
}
answered by (11.4k points) 14 23 31
selected by

Related questions

0 votes
1 answer 3.2k views
3.2k views asked by sara (24.6k points) 31 55 94
0 votes
1 answer 42 views
0 votes
1 answer 216 views
216 views asked by augustaina (4.8k points) 10 25 32
+1 vote
1 answer 37 views
37 views asked by keem (13.2k points) 28 44 63
...