How do I reverse an int array in Java?

前端 未结 30 2443
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 07:18

I am trying to reverse an int array in Java.

This method does not reverse the array.

for(int i = 0; i < validData.length; i++)
{
    int temp =          


        
30条回答
  •  旧时难觅i
    2020-11-21 07:56

    public void display(){
      String x[]=new String [5];
      for(int i = 4 ; i > = 0 ; i-- ){//runs backwards
    
        //i is the nums running backwards therefore its printing from       
        //highest element to the lowest(ie the back of the array to the front) as i decrements
    
        System.out.println(x[i]);
      }
    }
    

提交回复
热议问题