Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# Java I have some question about static and array: For example, in the first case: The list won't reverse. But in the second case:
# Java
I have some question about static and array:
For example, in the first case: The list won't reverse.
But in the second case: the numbers[0] is 3, the value of 3 is transfer from the static method m.
why ??
Case1:
public class Test { public static void main(String[] args){ int[] list = {1,2,3,4,5}; reverse(list); for(int i=0; iout.println(list[i]+ " "); } } public static void reverse(int[]list){ int [] newList = new int[list.length]; for(int i=0; i
__________________________________________________
Case2: public class Test { public static void main(String[] args){ int number =0; int[] numbers = new int[1]; m(number, numbers); System.out.println("number is :"+ number+" and numbers is :"+ numbers[0]); } public static void m(int x, int[]y){ x = 3; y[0] = 3; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started