Problem 1 on the course website. You must complete the program by implementing the following requirements. Don't forget to delete “_incomplete" from the file name. An incomplete Java program named Hwl_Pl_incomplete.java is posted This program has three methods. The first method receives an array of integers and calculates the average, the minimum, and the maximum of the integers and prints them on the screen. The signature of this method is: public static void stats(int[ ] numbers) is: The second method creates and prints a subarray of a given array. The specification of the method Signature of method: public static void subarray(int[ ] a, int from, int to) Input arguments: a: An array of integers from: The index of an element in a which becomes the first element in the subarray to: The index of an element in a which becomes the last element in the subarray Behavior: • A new integer array is created, which is a subarray of a, and it includes elements a[from] to a[to], inclusively. Prints the subarray. There is no return value. The third method is a main method. If you run this program with the following main method: public static void main(String[] args) { int[] a - {15, 25, 10, 65, 30, 55, 65}; System.out.print("\nGiven array is: "); for (int i=0; ica.length-1; i++) { System.out.print(a[i] + ", "); System.out.print(a[a.length - 1]); System.out.println(); stats(a); subarray(a, 1, 4);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

-------------HW1_P1_INCOMPLETE.JAVA,,,,,,,,,,,,,,,,,,,,,,,,,,

public class Hw1_part1 {

public static void stats(int[] a) {

// complete this method
}

public static void subarray(int[] a, int from, int to) {
// error check w/o using Java's exception handling
if (from < 0 || to >= a.length) {
System.out.println("Index out of bound");
return;
}

// complete this method

}

public static void main(String[] args) {

// test
int[] a = {15, 25, 10, 65, 30, 55, 65};

System.out.println("\nGiven array is: " + Arrays.toString(a));
stats(a);
subarray(a, 1, 4);

// test with other arrays
}

}

Problem 1
An incomplete Java program named Hwl_Pl_incomplete.java is posted
on the course website. You must complete the program by implementing the following
requirements. Don't forget to delete “_incomplete" from the file name.
This program has three methods. The first method receives an array of integers and calculates the
average, the minimum, and the maximum of the integers and prints them on the screen.
The signature of this method is:
public static void stats(int[ ] numbers)
The second method creates and prints a subarray of a given array. The specification of the method
is:
Signature of method:
public static void subarray(int[ ] a, int from, int to)
Input arguments:
a: An array of integers
from: The index of an element in a which becomes the first element in the subarray
to: The index of an element in a which becomes the last element in the subarray
Behavior:
• A new integer array is created, which is a subarray of a, and it includes elements
alfrom] to a[to], inclusively.
• Prints the subarray.
There is no return value.
The third method is a main method. If you run this program with the following main method:
public static void main(String[] args) {
int[] a = {15, 25, 10, 65, 30, 55, 65};
System.out.print("\nGiven array is: ");
for (int i=0; i<a.length-1; i++) {
System.out.print(a[i] + ", ");
}
System.out.print(a[a.length - 1]);
System.out.printin();
stats(a);
subarray(a, 1, 4);
Transcribed Image Text:Problem 1 An incomplete Java program named Hwl_Pl_incomplete.java is posted on the course website. You must complete the program by implementing the following requirements. Don't forget to delete “_incomplete" from the file name. This program has three methods. The first method receives an array of integers and calculates the average, the minimum, and the maximum of the integers and prints them on the screen. The signature of this method is: public static void stats(int[ ] numbers) The second method creates and prints a subarray of a given array. The specification of the method is: Signature of method: public static void subarray(int[ ] a, int from, int to) Input arguments: a: An array of integers from: The index of an element in a which becomes the first element in the subarray to: The index of an element in a which becomes the last element in the subarray Behavior: • A new integer array is created, which is a subarray of a, and it includes elements alfrom] to a[to], inclusively. • Prints the subarray. There is no return value. The third method is a main method. If you run this program with the following main method: public static void main(String[] args) { int[] a = {15, 25, 10, 65, 30, 55, 65}; System.out.print("\nGiven array is: "); for (int i=0; i<a.length-1; i++) { System.out.print(a[i] + ", "); } System.out.print(a[a.length - 1]); System.out.printin(); stats(a); subarray(a, 1, 4);
Your output should be:
Given array is: 15, 25, 10, 65, 30, 55, 65
average = 37.86, min = 10, max = 65
The subarray, from index 1 to index 4, is: 25, 10, 65, 30
Transcribed Image Text:Your output should be: Given array is: 15, 25, 10, 65, 30, 55, 65 average = 37.86, min = 10, max = 65 The subarray, from index 1 to index 4, is: 25, 10, 65, 30
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY