Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative number is not a part of the sorted list). Assume the number of integers is always odd. Ex: If the input is: 2 3 4 8 11 -1 the output is: Middle item: 4 The maximum number of list values for any test case should not exceed 9. If exceeded, output "Too many numbers". Hint: First read the data into an array. Then, based on the array's size, find the middle item.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 8PE
icon
Related questions
Question

I need help solving this in JAVA

Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative number is not a part
of the sorted list). Assume the number of integers is always odd.
Ex: If the input is:
2 3 4 8 1l -1
the output is:
Middle item: 4
The maximum number of list values for any test case should not exceed 9. If exceeded, output "Too many numbers".
Hint: First read the data into an array. Then, based on the array's size, find the middle item.
Transcribed Image Text:Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative number is not a part of the sorted list). Assume the number of integers is always odd. Ex: If the input is: 2 3 4 8 1l -1 the output is: Middle item: 4 The maximum number of list values for any test case should not exceed 9. If exceeded, output "Too many numbers". Hint: First read the data into an array. Then, based on the array's size, find the middle item.
1 import java.util.Scanner;
3 public class LabProgram {
public static void main(String args) {
Scanner scnr = new Scanner(System.in);
int[] userValues = new int[9]; // Set of data specified by the user
4
6.
8.
/* Type your code here. */
}
9.
10 }
11
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
Develop mode
Submit mode
second box.
Enter pregra m input lontion
Transcribed Image Text:1 import java.util.Scanner; 3 public class LabProgram { public static void main(String args) { Scanner scnr = new Scanner(System.in); int[] userValues = new int[9]; // Set of data specified by the user 4 6. 8. /* Type your code here. */ } 9. 10 } 11 Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the Develop mode Submit mode second box. Enter pregra m input lontion
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Mergesort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning