Write a Java program to input a number of values into an array and then process the array by
passing it to various methods that will compute and return information we are interested in. These
include:
1. the average of the values in the array
2. the standard deviation of the values in the array
3. the number of items in the array less than the average
4. whether the array’s values are in increasing order or not
First, you need to write main. Your main method have at least four variables:
An int array
A variable for the number of items in the array
A Scanner for input
A variable of type double to store the returned average
Run your program inputting the following values:
Number of items: 5
Items: 16 25 81 80 24
Output:
Average:
45.20
Std Dev:
32.41
Less than Avg: 3
Array is not in sorted order
Run your program on the following seven sets of inputs.
1. 5 inputs: 16 25 81 80 24 (the output for this is shown above to test)
2. 10 inputs: 1000 1001 1111 1222 1775 1776 1777 1888 1997 1998
3. 1 input: 1000 (this should cause an error message that it cannot compute standard deviation)
4. 10 inputs: 1 2 3 9 8 7 4 6 12 15
5. 0 inputs (this should cause error messages that the number of inputs is out of range)
6. 20 inputs: 21 3 20 5 30 1 33 14 17 18 10 4 48 50 22 25 6 47 8 19
7. 10 inputs: 8 7 8 7 8 7 9 8 9 7
Source Code in Java:
import java.util.Scanner;
class ArrayStats
{
static double average(int arr[]) //function to calculate average of
elements in an array
{
double total=0.0;
for(int i=0;i<arr.length;i++)
total+=arr[i]; //storing sum of elements in total
return total/arr.length; //calculating and returning average
}
static double standard_deviation(int arr[]) //function to calculate
standard deviation of elements in an array
{
double average=average(arr);
double total=0.0;
for(int i=0;i<arr.length;i++)
total+=(arr[i]-average)*(arr[i]-average);
return Math.sqrt(total/(arr.length-1));
}
static int less_than_average(int arr[]) //function to check number
of elements less than average in an array
{
double average=average(arr);
int count=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]<average)
count++;
}
return count;
}
static boolean is_increaing(int arr[]) //function to check if an
array is in increasing order
{
for(int i=0;i<arr.length-1;i++)
{
if(arr[i]>arr[i+1])
return false;
}
return true;
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n;
System.out.print("Size of array: "); //input prompt
n=in.nextInt(); //input
//validating input
if(n<=0)
{
System.out.println("Size of array is out of range. Try again with a
valid size.");
return;
}
if(n==1)
{
System.out.println("Cannot compute Standard Deviation. Try again
with a valid size.");
return;
}
int arr[]=new int[n]; //creating new array
System.out.println("Enter the elements one by one: "); //input
prompt
for(int i=0;i<n;i++)
arr[i]=in.nextInt(); //input
//outputs
System.out.println("Average: "+average(arr));
System.out.println("Standard Deviation:
"+standard_deviation(arr));
System.out.println("Count of numbers less than average:
"+less_than_average(arr));
System.out.println("Array is "+(is_increaing(arr)?"":" not ")+"in
sorted order");
}
}
Output:

Write a Java program to input a number of values into an array and then process...
Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...
Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...
Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...
(C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...
I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....
JAVA:
(15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...
Write a Java program that takes an int array as input, and returns the average of all the values in the array. No class construction is necessary; however, the complete signature and definition and brief documents are needed.
****WRITE A JAVA PROGRAM THAT : Write a method named stretch that accepts an array of integers (that the user inputs) as a parameter and returns a new array twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original. If a number in the original array is odd, then the first number in the new pair should be one higher than the second so that the sum equals...
Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.
For Java Write a program that reads a sequence of integer inputs all on one line and prints: 1.)The smallest and largest of the inputs 2.)The number of odd and even inputs 3.)Cumulative totals. If the input is 1 7 2 9, the program prints 1 8 10 19. 4.)All adjacent duplicates. If the input is 1 3 3 4 5 5 6 6 6 2, the output is 3 5 6.