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)
- Using functions, create a program that reads three integer values, and then determines whether they can be the sides of a triangle.(the numbers. Notes: The values can represent the sides of a triangle if the sum of any two sides of the triangle is greater than the third sidearrow_forward(Temperature Conversions) Implement the following integer functions:a) Function toCelsius returns the Celsius equivalent of a Fahrenheit temperature.b) Function toFahrenheit returns the Fahrenheit equivalent of a Celsius temperature.c) Use these functions to write a program that prints charts showing the Fahrenheit equivalents of all Celsius temperatures from 0 to 100 degrees, and the Celsius equivalents ofall Fahrenheit temperatures from 32 to 212 degrees. Print the outputs in a tabular format that minimizes the number of lines of output while remaining readable.arrow_forward[Python (py3)] The error in the code below is if the number of rows of the matrix is not equal to its number of columns, matrix addition will not be performed. This should not be the case since the only requirement for matrices addition is that the dimension of Matrix A is equal to the dimension of Matrix B. Please resolve the error in the code below such that Matrix A and Matrix B can be added if the dimension of Matrix A is equal to the dimension of Matrix B. PLEASE do not just copy the code below and use it as the answer itself. I've encountered such case many times. Please modify the code. When the dimension of Matrix A is not equal to the dimension of Matrix B, print "Matrix addition cannot be performed; dimensions are unequal." The input will come from file1.txt, and the output should only be printed to output.txt Format of the input from file1.txt:First Line: type of operation (add)Second Line: matrix A dimension (example: if 3 rows and 2 columns, type 3 2)Third Line: matrix A…arrow_forward
- (Average a Sequence of Integers) Write a program that calculates and prints the average ofseveral integers. Assume the last value read with scanf is the sentinel 9999. A typical input sequencemight be10 8 11 7 9 9999indicating that the average of all the values preceding 9999 is to be calculatedarrow_forward(Quality Points for Student’s Grades) Write a function toQualityPoints that inputs a student’s average and returns 4 it’s 90–100, 3 if it’s 80–89, 2 if it’s 70–79, 1 if it’s 60–69, and 0 if theaverage is lower than 60arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning