- Joined
- Jul 29, 2005
- Location
- Kenner, LA
Hey guys I'm trying to multiply every element of a 2D array by a double but I'm getting erroneous output.
This is the main file:
And this is the class which has the method that does the multiplication:
This is my input file:
So basically I have stored all the integers of this file in a 2-D array and i want to multiply each element by 195.85 and store the result into another 2-D array. This is the output that I am getting
Output:
Any help is greatly appreciated guys.
This is the main file:
Code:
import java.io.*;
import java.util.Scanner;
public class prog5
{
public static void main(String[] args) throws FileNotFoundException
{
String[] names = new String[10];
String first, last;
int[][] ints = new int[10][4];
double[][] individual_month_sales = new double[10][4];
Sales one = new Sales();
File inFile = new File("fal.data");
Scanner in = new Scanner(inFile);
int count = 0;
while(in.hasNext())
{
last = in.next();
first = in.next();
names[count] = last + first;
for(int row=0; row < 10; row++){
for(int col=0; row < 4; row++){
ints[row][col] = in.nextInt();
}
}
count++;
}
one.monthlySales(ints, individual_month_sales);
for(int n=0; n<10; n++)
{
for(int m=0; m<4; m++)
{
System.out.println(individual_month_sales[n][m]);
}
}
}
}
And this is the class which has the method that does the multiplication:
Code:
class Sales
{
private int[][] integer_data;
private double[][] month_sales;
public void monthlySales(int[][] integer_data, double[][] month_sales)
{
for(int i=0; i<10; i++)
{
for(int j=0; j<4; j++)
{
month_sales[i][j] = 195.85 * integer_data[i][j];
}
}
}
}
This is my input file:
Code:
Manyana, Michael 30 25 45 18
Henderson, Marge 22 30 32 35
Striker, Nancy 32 30 33 31
Johnson, Fred 12 17 19 15
Ryan, Renee 22 17 28 16
Anderson, Roy 15 18 19 20
Bendix, Sue 21 25 20 23
Sparks, Angie 25 27 23 28
Calhoun, Drew 31 30 29 28
Zilder, Zeek 15 11 12 14
So basically I have stored all the integers of this file in a 2-D array and i want to multiply each element by 195.85 and store the result into another 2-D array. This is the output that I am getting
Output:
Code:
2937.75
0.0
0.0
0.0
2154.35
0.0
0.0
0.0
2350.2
0.0
0.0
0.0
2741.9
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
Any help is greatly appreciated guys.