So im doing this multidirectional array exercise and have copied from the book. Object Orientated Programming With Java. C thomas Wu page 595.
It makes sense to me the array has two aspects [][], accessed using array[][] etc
In the last part to add 1.50 to each and then display it. Problem is all of a sudden it cant find j when used as an index.
Is the book wrong?
The following is the code.
class PayScaleTable
{
public static void main (String[]args){
double [][] payScaleTable = {
{10.50,12.00,14.50,16.75,18.00},
{20.50,22.25,24.00,26.25,28.00},
{34.00,36.50,38.00,40.35,43.00},
{50.00,60.00,70.00,80.00,99.99}};
System.out.println("\n");
System.out.println("\n");
//Avg pay of level 2 ppl
double sum = 0.00, average;
for (int j=0; j<5;j++){
sum += payScaleTable[2][j];
}
average = sum / 5;
System.out.println("lvl 2employees " + average);
System.out.println("\n");
System.out.println("\n");
//pay difference in grades
double difference;
for(int i=0; i<4;i++){
difference = payScaleTable[i][4] - payScaleTable[i][0];
System.out.println("pay diff " + i + " is " + difference);
}
System.out.println("\n");
System.out.println("\n");
//print out pay scale table
for (int i=0; i<payScaleTable.length;i++){
for(int j=0; j<payScaleTable[i].length; j++){
System.out.print(payScaleTable[i][j] + " ");
}
System.out.print(" ");
}
System.out.println("\n");
System.out.println("\n");
//increase by 1.40 and display results
for(int i=0;i<payScaleTable[i].length;i++){
for(int j=0;j<payScaleTable[i].length;j++)
payScaleTable[i][j] += 1.50;
System.out.print(payScaleTable[i][j] + " ");
}
System.out.println(" ");
}
}