Name: Anonymous 2011-11-22 17:25
I've been working on this program for class but, while it has no errors in the code itself, it's not doing what I need it to do.
It's not giving right answers, or the right layout so I'm sure it's just a small error in the math section. The goal is for a user to enter the low number, and then the high number, and display the multiplication of each intersection. (If the low number is 1 and the high number is 5, it would display
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
If someone could check it for me quickly, I'd really appreciate it.
------------------
import java.util.*;
public class Multitable
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int lowNumber, highNumber;
System.out.print("Enter a number: ");
lowNumber = keyboard.nextInt();
System.out.print("Enter another number: ");
highNumber = keyboard.nextInt();
System.out.println("Here you go: A " + lowNumber + " by " + highNumber +
" multiplication table.");
double[][] multiTable = new double[lowNumber][highNumber];
for (int row=0;row<lowNumber;row++)
{
for (int col=0;col<highNumber;col++)
{
multiTable[row][col] = row+1 * col+1;
System.out.print(multiTable[row][col] + " ");
}
System.out.println();
}
}
}
It's not giving right answers, or the right layout so I'm sure it's just a small error in the math section. The goal is for a user to enter the low number, and then the high number, and display the multiplication of each intersection. (If the low number is 1 and the high number is 5, it would display
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
If someone could check it for me quickly, I'd really appreciate it.
------------------
import java.util.*;
public class Multitable
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int lowNumber, highNumber;
System.out.print("Enter a number: ");
lowNumber = keyboard.nextInt();
System.out.print("Enter another number: ");
highNumber = keyboard.nextInt();
System.out.println("Here you go: A " + lowNumber + " by " + highNumber +
" multiplication table.");
double[][] multiTable = new double[lowNumber][highNumber];
for (int row=0;row<lowNumber;row++)
{
for (int col=0;col<highNumber;col++)
{
multiTable[row][col] = row+1 * col+1;
System.out.print(multiTable[row][col] + " ");
}
System.out.println();
}
}
}