java - Dividing values from one array by values from a separate array -


i trying take values separate arrays , perform divisional math. have created method perform division, keep getting "bad operand..." error. have searched , searched, cannot find resolution. need able take values tripmiles , divide values gallons.

import java.util.scanner;  public class week6challenge {         public static void main(string[] args) {         scanner scan = new scanner (system.in);         int count = 0;         //double miles = 0, gallons = 0;         //arrays         string[] tripname;         tripname = new string[11];         double[] tripmiles;         tripmiles = new double[11];         double[] tripmpg;         tripmpg = new double [11];         double[] gallons;         gallons = new double [11];          //double miles = 0, gallons = 0;          while (count <= 9){//start while             system.out.println("enter description of trip");             tripname[count] = scan.next();              system.out.println("how many miles did drive?");             tripmiles[count] = scan.nextdouble();              system.out.println("how many gallons of gas did use on trip");             gallons[count] = scan.nextdouble();             count++;         }//end while          tripmpg[count] = answer(tripmiles, gallons);          system.out.println("trip name \t miles traveled \t mpg");         int k = 0;         for(k = 0; k < 10; k++){             system.out.println(tripname[k]+ "\t\t" + tripmiles[k] + "\t\t\t" + tripmpg[k]);         }     }     public static double answer(double[] num1, double[] num2){         return (num1/num2);     } } 

you trying divide 2 arrays like:

return (num1/num2); 

which not valid.

instead if need length or sum of 2 arrays , divide, sum elements , divide 2 values.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -