Question: Your friend is looking at the previous code and he is wondering why after calling foo() a is not modified but the array b is

Your friend is looking at the previous code and he is wondering why after calling foo() a is not modified but the array b is modified. How can you explain this? Is it expected?

public static void foo(int n, int[] w) { n = 1; w[0] = 2; w[1] = 3; w[2] = 4; } public static void main(String[] args) { int a = 0; int[] b = {0, 0, 0}; System.out.println(" a: " + a + " b: " + Arrays.toString(b)); foo(a, b); System.out.println(" a: " + a + " b: " + Arrays.toString(b)); }

Output:

a: 0 b: [0, 0, 0] a: 0 b: [2, 3, 4]

Write a method isSorted() which takes in an array of integers and returns true if the numbers are sorted from smallest to largest.

Then, write a method called reverseAll(). This method will take in an array of Strings and modify the array so that all the Strings in the array are reversed. Because this method modifies the contents of the array being passed in, it does not return anything. An example:

["apple", "banana", "racecar", "abc" ] will become ["elppa", "ananab", "racecar", "cba"] 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!