Problem

What is pass-by-value? Show the result of the following programs.(a)public class Test {pub...

What is pass-by-value? Show the result of the following programs.

(a)

public class Test {

public static void main(String[] args) {

int max = 0;

max(1, 2, max);

System.out.println(max);

}

public static void max(

int value1, int value2, int max) {

if (value1 > value2)

max = value1;

else

max = value2;

}

}

(b)

public class Test {

public static void main(String[] args) {

int i = 1;

while (i <= 6) {

method1(i, 2);

i++;

}

}

public static void method1(

int i, int num) {

for (int j = 1; j <= i; j++) {

System.out.print(num + " ");

num *= 2;

}

System.out.println();

}

}

(c)

public class Test {

public static void main(String[] args) {

// Initialize times

int times = 3;

System.out.println("Before the call,"

+ " variable times is " + times);

// Invoke nPrintln and display times

nPrintln("Welcome to Java!", times);

System.out.println("After the call,"

+ " variable times is " + times);

}

// Print the message n times

public static void nPrintln(

String message, int n) {

while (n > 0) {

System.out.println("n = " + n);

System.out.println(message);

n--;

}

}

}

(d)

public class Test {

public static void main(String[] args) {

int i = 0;

while (i <= 4) {

method1(i);

i++;

}

System.out.println("i is " + i);

}

public static void method1(int i) {

do {

if (i % 3 != 0)

System.out.print(i + " ");

i--;

}

while (i >= 1);

System.out.println();

}

}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
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