Multiplication of a 2D array by a 1D array in java -


i'm having trouble figuring out how multiply columns of 2d array 1d array...

              item  store   0   1   2   3    4  0      25  64  23  45  14  1      12  82  19  34  63  2      54  22  17  32  35  item     cost per item    1           $12.00    2           $17.95    3           $95.00    4           $86.50    5           $78.00 

i have multiply columns of 2d array symbolize items cost (i.e. column 1 2d array $12.00, column 2 (2d array) $17.95.

what i'm having trouble understanding how program multiply columns instead of rows , columns, appreciated.

edit:

import java.util.*; public class asd {     public static void main(string[] args)     {         double items[][]= new double[3][5];         double cost[]=new double[5];         loadarray(items, cost);         system.out.println("total amount of sales each store : ");         computecost(items, cost);         printarray(items, cost);     }     public static void loadarray(double items[][], double cost[])     {         scanner input = new scanner(system.in);         string s1;         int num, x, y;         for(x=0; x<items.length;x++)         {             for(y=0; y<items[x].length; y++)             {                 system.out.println("enter next item of data:");                 items[x][y]=input.nextdouble();             }         }          //cost of items:         cost[0]=12.99;         cost[1]=17.95;         cost[2]=95.00;         cost[3]=86.50;         cost[4]=78.00;     }     public static void printarray(double items[][], double cost[])      {         system.out.println("number of items sold during day: ");         int row, col;         (row =0;  row<items.length ; row++)         {             for(col=0; col<items[row].length; col++)             {                 system.out.print( items[row][col]+" ");             }             system.out.println();         }         system.out.println("cost per item: ");         int i;         (i =0; < 5; i++)         {             system.out.println(cost[i]);         }     }     public static void computecost (double items[][], double cost[])     {         int row, col;         double productarray[]=new double[5];         (row =0;  row<items.length ; row++)         {             for(col=0; col<items[1].length; col++)             {                 productarray[row]=items[row][col] * cost[0];             }             system.out.println("test: "+productarray[row]);         }     } } 

the loop have first column:

         double a,b,c;         a=items[0][0]*cost[0];         system.out.println("test 12.99*25: "+a);         b=items[1][0]*cost[0];         system.out.println("test 12.99*12: "+b);         c=items[2][0]*cost[0];         system.out.println("test 12.99*54: "+c); 

edit: finished program people commented.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -