How do I swap two integers in an array, where my method takes in two integers and an array from main?

后端 未结 4 727
既然无缘
既然无缘 2020-12-12 06:17

I call my swap method in main, but it doesn\'t change anything. What am I doing wrong?

public static void main(String[] args){


    int mainArr[] = new int[         


        
4条回答
  •  执笔经年
    2020-12-12 07:04

    Writing the code as so:

    int mainArr[] = new int[20];  
    
    for(int i =0; i 

    will resolve the issue. The problem was you happened to be calling swap an even number of times, so it had a total effect of nothing.

提交回复
热议问题