Hello guys......Cindy here
I am trying to get my program working and I am getting really frustrated. I am writing this program to familiarise myself with arrays, methods & loops so i can improve my Java skills.
Im not lazy guys and have tried searching yahoo ,answers, forums and google for some answers but cant find what im looking for.
what i'm trying to do is write a program that given a set of numbers to be stored in an array, calculates and outputs the following to the screen:
* the total of the numbers entered((i know this bit works))
* the largest number
* the smallest number
* the average of the numbers
* the middle value
here is what i have so far
class javaprogram
{
public static void main(String []args)
{
int total=0; //used to store the total of the array item.
System.out.println("How many numbers do you wish to enter?");
int n = EasyIn.getInt();
//declare array called numbers
int[] numbers = new int[n];
//fill the array with numbers read in by the user.
for(int i = 0; i< numbers.length; i++)
{
System.out.println("Enter number " + (i+1));
numbers[i] = EasyIn.getInt();
}
//call the method 'totalMethod'
//passing the array 'numbers' as an arument
System.out.println("Total is " + totalMethod(numbers));
System.out.println("The biggest number is " + biggest(numbers));
System.out.println("The smallest number entered is " + smallest(numbers));
System.out.println("The average value entered is " + average(numbers));
System.out.println("The middle value entered is " + middle(numbers));
}
// end main
public static int totalMethod(int[] nums)
{
// variable total used to accumulate the totals in the array.
int total = 0;
for (int i=0; i < nums.length; i++)
{
total = total + nums[i];
}
return total;
}// end totalMethod
public static int biggest(int[] nums)
{
//variable biggest used to calculate biggest number.
int biggest = (int [] nums)
{
int largest = nums[0];
for (int count =0; count > nums.length; count ++) {
if (intArray [count] > largest)
largest = nums [count];
}
return largest;
public static int smallest(int[] nums)
{
//variable smallest used to calculate smallest number
int smallest (int [] nums)
{
int least = nums[0];
for (int count =0; count < nums.length; count ++) {
if (nums [count] < least)
least = nums [count];
}
return least;
}
public static double average(int[] nums)
//variable average used to calculate the average value
int average (int [] nums)
{
//end main
am i correct in thinking that i have to create a different method for each of the calculations i want to return?
Hope someone can help or even point me in the right direction, i have no idea how to calculate the average or the middle value entered and need some advice
Thanks guys
Cindy