Write a java program that: Declare an array capable of holding 4 integers. It must be 4 integers only in the declaration. int[ ] array = new int[4]; Loop prompting the user to enter values to insert into the array until they enter a -1. For simplicity, we will assume users will only enter values greater than 0. You will need to check to see if the array is full before inserting the value in the next available spot in the array. If the array is full you will need to invoke the method, public static int[] expandArray(int[ ] array) that will double the size of the array and copy in the contents of the array. Include the method public static void displayArray(int[ ] array) that will display the contents of the array. Your main will contain the loop that prompts user to enter a value or -1 to indicate to quit. User will only enter values greater than 0. Insert the value into the next available slot in the array. You need to check to see if there is room in the array prior to inserting. After the user enters -1 and the loop terminates, display the contents of the array by calling displayArray. Hint: your main will want to keep track of the next available index into the array. When testing your program try to enter 10 values. Hint: See ExpandArray.java and for an example. Sample run: Please enter values to insert into the array or -1 to quit. 5 15 4 12 3 6 8 22 16 11 -1 The contents of the array: Index Value 0 5 1 15 2 4 3 12 4 3 5 6 6 8 7 22 8 16 9 11
Write a java program that: Declare an array capable of holding 4 integers. It must be 4 integers only in the declaration. int[ ] array = new int[4]; Loop prompting the user to enter values to insert into the array until they enter a -1. For simplicity, we will assume users will only enter values greater than 0. You will need to check to see if the array is full before inserting the value in the next available spot in the array. If the array is full you will need to invoke the method, public static int[] expandArray(int[ ] array) that will double the size of the array and copy in the contents of the array. Include the method public static void displayArray(int[ ] array) that will display the contents of the array. Your main will contain the loop that prompts user to enter a value or -1 to indicate to quit. User will only enter values greater than 0. Insert the value into the next available slot in the array. You need to check to see if there is room in the array prior to inserting. After the user enters -1 and the loop terminates, display the contents of the array by calling displayArray. Hint: your main will want to keep track of the next available index into the array. When testing your program try to enter 10 values. Hint: See ExpandArray.java and for an example. Sample run: Please enter values to insert into the array or -1 to quit. 5 15 4 12 3 6 8 22 16 11 -1 The contents of the array: Index Value 0 5 1 15 2 4 3 12 4 3 5 6 6 8 7 22 8 16 9 11
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...
Related questions
Question
Write a java program that:
- Declare an array capable of holding 4 integers. It must be 4 integers only in the declaration. int[ ] array = new int[4];
- Loop prompting the user to enter values to insert into the array until they enter a -1. For simplicity, we will assume users will only enter values greater than 0.
- You will need to check to see if the array is full before inserting the value in the next available spot in the array.
- If the array is full you will need to invoke the method,
public static int[] expandArray(int[ ] array)
that will double the size of the array and copy in the contents of the array.
- Include the method
public static void displayArray(int[ ] array)
that will display the contents of the array.
- Your main will contain the loop that prompts user to enter a value or -1 to indicate to quit. User will only enter values greater than 0. Insert the value into the next available slot in the array. You need to check to see if there is room in the array prior to inserting. After the user enters -1 and the loop terminates, display the contents of the array by calling displayArray. Hint: your main will want to keep track of the next available index into the array.
- When testing your program try to enter 10 values.
Hint: See ExpandArray.java and for an example.
Sample run:
Please enter values to insert into the array or -1 to quit.
5
15
4
12
3
6
8
22
16
11
-1
The contents of the array:
Index Value
0 5
1 15
2 4
3 12
4 3
5 6
6 8
7 22
8 16
9 11
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY