Qusay Abu Auda :
I hope that you are fine and doing well.
public class Main {
public static void main(String[] args) {
System.out.println(reverse3(new int[] {1,2,3}));
}
public static int[ ] reverse3(int [] nums) {
int [] j = new int[3];
j[0] = nums[2];
j[1] = nums[1];
j[2] = nums[0];
return j;
}
}
As you see in the code the method is given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}.
But when I click to run the final result is [I@7b23ec81 Can anyone tell me the solution and thanks.
Ayushi Keshri :
Because you are returning j which is an array object, you need to loop it out to print the values
In main function what you can do is:
Array arr[] = reverse3(new int[]{1,2,3});
for(int i=0;i<arr.length;i++)
{ System.out.println(arr[i]); }
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=334226&siteId=1