Could I get some help with this data structure to consider the following method with integer value x.
public static test(int x)
{
x += 2;
}
Suppose y has a value of 10, then the method is activated test(y) what is the value of y after this activation?
Answer: 12
Explanation:
The statement x+=2; works like x=x+2;
As you asked if we initialize y with 10 y=10
and called test(y);
then y = y+2;
Therefore y =12;
In coding form:
public class Tester2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Initializing y with 10
int y= 10;
//calling the test function
System.out.println("value of y before calling test: "+y);
y= test (y);
//printing the value of y after test activation
System.out.println("value of y after calling test: "+y);
}
public static int test(int x) {
// TODO Auto-generated method stub
x += 2;
return x;
}
}
Output:

Could I get some help with this data structure to consider the following method with integer...