java - Need help referencing in an array and with number formatting -


i'm lost on assignment , need hand! basically, i'm suppose write code users can input number of inches of rain per month 12 months. calculate total inches, average inches, plus point out month , least rain. have total , average inches under control.

the , least rain i'm having issues though. know how write code figure out highest , least amount of rain fall, don't know how actual month in output. wants me list actual number in array of 12 months, instance, 7 seventh month.

another issue i'm having decimal format. i've put import statement @ top, , put thought right code in thought right place in body, yet when average calculated, still produces long string of numbers. ie 12.12121314141, when want display 12.1.

any appreciated. thank in advance! here's code:

import java.util.scanner; import java.text.decimalformat;  public class rainfall {    public static void main (string [] args)    {       final int months = 12;    double[] rainfall = new double[months];     initrain(rainfall);     decimalformat formatter = new decimalformat("##0.0");    system.out.println("the total rainfall year " +                    totalrain(rainfall));    system.out.println("the average rainfall year " +              averagerain(rainfall));    system.out.println("the month highest amount of rain " +                  highest);    system.out.println("the month lowest amount of rain " +                leastrain(rainfall));         }     /**   totalrain method   @return total rain fall in array.    */     public static double totalrain(double[] rainfall)    {       double total = 0.0;     // accumulator    // accumulate sum of elements in rain fall array   (int index = 0; index < rainfall.length; index++)      //total += rainfall[index];      total = total + rainfall[index];    // return total.       return total;    }     /**   averagerain method    @return average rain fall in array.    */     public static double averagerain(double[] rainfall)    {       return totalrain(rainfall) / rainfall.length;    }     /**   mostrain method   @return rain in rain fall array.    */     public static double mostrain(double[] rainfall)    {   double highest = rainfall[0];    (int index = 0; index < rainfall.length; index++)   {      if (rainfall[index] > highest)         highest = rainfall[index];   }    return highest;    }     /**   leastrain method   @returns least rain in rain fall array.    */     public static double leastrain(double[] rainfall)    {   double lowest = rainfall[0];    (int index = 0; index < rainfall.length; index++)   {      if (rainfall[index] < lowest)         lowest = rainfall[index];   }    return lowest;    }        /**   initrain method    @return rain fall array filled user input    */ public static void initrain(double[] array) {       double input;  // hold user input.   scanner scan = new scanner(system.in);        (int index = 0; index < array.length; index++)   {     system.out.print("enter rain fall month " + (index + 1)                   +": ");     array[index] = scan.nextdouble();       } } } 

for format issue, make this:

system.out.println("the total rainfall year " +       formatter.format(totalrain(rainfall))); 

and on return values.

i don't issue regarding months thou. explain little more?

edit. okay, it. value of index inside loop when assign higuestrain,... values month searching ; )


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -