Question: Can someone please fix my code and explain it please I have been struggling. It keeps outputting the middle term but I want it to

Can someone please fix my code and explain it please I have been struggling. It keeps outputting the middle term but I want it to only output "Too many numbers" when the following is used as input: 102030405060708090100110-1
My code is as follows:
import java.util.Scanner;
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
int count =0;
boolean keepGoing = true;
while(keepGoing)
{
int numbers = scnr.nextInt();
if(numbers 0)
{
keepGoing = false;
}
else if(count userValues.length)
{
userValues[count]= numbers;
count++;
}
else
{
System.out.println("Too many numbers");
keepGoing = false;
}
}
if(userValues[count -1]>0)
{
int midVal = count /2;
System.out.println("Middle item: "+ userValues[midVal]);
}
}
}
Can someone please fix my code and explain it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!