Question

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

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?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

Add a comment
Know the answer?
Add Answer to:
Could I get some help with this data structure to consider the following method with integer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT