Concept explainers
(a)
Given Program:
public class Test {
//Main Method
public static void main(String[] args) {
//Initialize number
int number = 0;
int[] numbers = new int[1];
m(number, numbers);
//Display the number
System.out.println("number is " + number
+ " and numbers[0] is " + numbers[0]);
}
public static void m(int x, int[] y) {
x = 3;
y[0] = 3;
}
}
(b)
Given Program:
import java.util.Scanner;
public class Test{
//Main Method
public static void main(String[] args) {
//Initialize the numbers
int[] list = {1, 2, 3, 4, 5};
reverse(list);
//Display the list
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}
//Method to find the reverse
public static void reverse(int[] list) {
int[] newList = new int[list.length];
for (int i = 0; i < list.length; i++)
newList[i] = list[list.length - 1 - i];
list = newList;
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning