Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will read in a list of positive integers (including zero) a

ID: 3621989 • Letter: W

Question

Write a program that will read in a list of positive integers (including zero) and display some statistics regarding the integers.

The user is assumed to enter the list in sorted order, starting with the smallest number and ending with the largest number.

Your program must store the all of the integers in an array. The maximum number of integers that you can expect is 100, however there may not necessarily be that many. Your program should allow the user to continue entering numbers until they enter a negative number or until the array is filled - whichever occurs first. If the user enters 100 numbers, you should output an message stating that the maximum size for the list has been reached, then proceed with the calculations.

After you have placed all of the integers into an array, your program should perform the following tasks, in this order:

Display the count of how many numbers were read


Display the smallest number in the array


Display the largest number in the array


Display the median (the median is the integer that is stored in the middle position of the array)


Display the average of all the numbers


Allow the user to search the array for a specified value.
First, ask the user to enter an integer to search for.

Next, search the array to determine if the given integer is in the array.

If the integer is not found, display a message stating that the integer is not in the list.
If the integer is found, then display the position number of where you found the integer. If the integer happens to be in the array more than once, then you only need to tell the first position number where you found it.

After performing the search, ask the user if he/she wants to search for more integers. Continue searching for numbers until the user answers "N".

Explanation / Answer

please rate - thanks

import java.util.*;
public class statistics
{public static void main(String args[])
{int[] number = new int[100];
double average=0,median;
int i=0,j,sum=0,n;
String in;
boolean found;
char yorn;
Scanner input= new Scanner(System.in);
System.out.print("Enter number (<0 to exit) " + (i+1) +":");
number[i]=input.nextInt();
while(number[i]>=0&&i<99)
{i++;
System.out.print("Enter number (<0 to exit) " + (i+1)+ ":");
number[i]=input.nextInt();
}
for(j=0;j<i;j++)
      sum+=number[j];
average=(double)sum/i;
System.out.println("The numbers read are: ");
for(j=0;j<i;j++)
System.out.print(number[j]+" ");
System.out.println();
System.out.println("Numbers read: "+i);
System.out.println("Smallest number: "+number[0]);
System.out.println("Largest number: "+number[i-1]);
if(i%2==0)
    median=(number[i/2 ]+number[i/2-1])/2.;
else median=number[i/2];
System.out.println("median: "+median);
System.out.println("The average is " + average);
do
{System.out.println("Enter a number to search for: ");
n=input.nextInt();
found=false;
for(j=0;j<i;j++)
     {if(number[j]==n)
         {System.out.println(n +" found at position "+ j);
           found=true;
            }
        }
    System.out.println(j);
    if(!found)
          System.out.println(n+" not found");
    System.out.println("Look for another number?(N to exit)");
    in=input.next();
    yorn=in.charAt(0);
    }while(Character.toUpperCase(yorn)!='N');

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote