1. Declare a reference variable to an array of integer elements. The name of the variable is listl. Remember that the syntax for declaring a reference variable is: elementType [] refVariable; 2. Print the reference variable to the console, as in the statement below, and observe and understand what happens. Then, remove the print statement. System.out.println(list1); 3. Create an array of 50 integer values, and assign its reference to the variable list1. Remember that the syntax for creating an array is: new elementType[arraySize]; In order to assign the returned reference to a reference variable, we put the new statement to the right of an assignment statement to a reference variable. refVariable = new elementType[arraySize] 4. Combine array declaration and creation such that they are on the same line as in the following syntax: elementType [] refVariable= new elementType[arraySize]; 5. Try to print the value of the reference variable to the console again, and observe the output. 6. Print the values of the array elements all on the same line space separated using a "for" loop. For this part, use a for loop with the following header: for(int i=0; i

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
7. Assign values to the array elements using a "for" loop with a header similar to that in
the previous step, such that each element has the value of the double of its index (i.e.
for element with index i the value is 2*i).
8. Print elements values to the console again, on the same line space separated, this time
using the "foreach" statement as follows:
foreach(int e:list1)
//print statement
Make sure to print a new line after printing the array elements.
9. Compute the average of the array list1 elements and print it to the console in the
following format:
Average is:
2/3
....
10.Count the number of elements in list1 that are greater than the average and print the
count to the console as follows:
Count is:
11.Modify the array list1 such that it includes only elements of it that are greater than the
computed average.
Print the elements of list1 after being modified.
12. Declare and create a new array, named list2, of the following integer values using an
array initializer:
16 8 12 6 18 4
Remember that the syntax for creating an array using array
elementType [] refVariable = {element1, element2, element3, ...}
initializer:
Remember you cannot separate the declaration and the creation of the array on two
separate lines when using array initializers.
13.Add the elements 1,3,5,7,9 to the array list2. Print the array elements after the new
elements are added.
14. Write a code that finds the element with the largest value in the array list2 and print it
to the console along with its index, in the following format:
Element with index .. and value .. is the largest.
Transcribed Image Text:7. Assign values to the array elements using a "for" loop with a header similar to that in the previous step, such that each element has the value of the double of its index (i.e. for element with index i the value is 2*i). 8. Print elements values to the console again, on the same line space separated, this time using the "foreach" statement as follows: foreach(int e:list1) //print statement Make sure to print a new line after printing the array elements. 9. Compute the average of the array list1 elements and print it to the console in the following format: Average is: 2/3 .... 10.Count the number of elements in list1 that are greater than the average and print the count to the console as follows: Count is: 11.Modify the array list1 such that it includes only elements of it that are greater than the computed average. Print the elements of list1 after being modified. 12. Declare and create a new array, named list2, of the following integer values using an array initializer: 16 8 12 6 18 4 Remember that the syntax for creating an array using array elementType [] refVariable = {element1, element2, element3, ...} initializer: Remember you cannot separate the declaration and the creation of the array on two separate lines when using array initializers. 13.Add the elements 1,3,5,7,9 to the array list2. Print the array elements after the new elements are added. 14. Write a code that finds the element with the largest value in the array list2 and print it to the console along with its index, in the following format: Element with index .. and value .. is the largest.
1. Declare a reference variable to an array of integer elements. The name of the variable
is listl.
Remember that the syntax for declaring a reference variable is:
elementType [] refVariable;
2. Print the reference variable to the console, as in the statement below, and observe and
understand what happens. Then, remove the print statement.
System.out.println(list1);
3. Create an array of 50 integer values, and assign its reference to the variable list1.
Remember that the syntax for creating an array is:
new elementType[arraySize];
In order to assign the returned reference to a reference variable, we put the new
statement to the right of an assignment statement to a reference variable.
refVariable = new elementType[arraySize]
%3D
4. Combine array declaration and creation such that they are on the same line as in the
following syntax:
elementType [] refVariable= new elementType[arraySize];
5. Try to print the value of the reference variable to the console again, and observe the
output.
6. Print the values of the array elements all on the same line space separated using a "for"
loop. For this part, use a for loop with the following header:
for(int i=0; i<list1.length; i++)
//print statement
Make sure to print a new line after printing the array elements.
Transcribed Image Text:1. Declare a reference variable to an array of integer elements. The name of the variable is listl. Remember that the syntax for declaring a reference variable is: elementType [] refVariable; 2. Print the reference variable to the console, as in the statement below, and observe and understand what happens. Then, remove the print statement. System.out.println(list1); 3. Create an array of 50 integer values, and assign its reference to the variable list1. Remember that the syntax for creating an array is: new elementType[arraySize]; In order to assign the returned reference to a reference variable, we put the new statement to the right of an assignment statement to a reference variable. refVariable = new elementType[arraySize] %3D 4. Combine array declaration and creation such that they are on the same line as in the following syntax: elementType [] refVariable= new elementType[arraySize]; 5. Try to print the value of the reference variable to the console again, and observe the output. 6. Print the values of the array elements all on the same line space separated using a "for" loop. For this part, use a for loop with the following header: for(int i=0; i<list1.length; i++) //print statement Make sure to print a new line after printing the array elements.
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