Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Multiplication Array

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();
        }
    }

}

Name: Anonymous 2011-11-22 20:15


#include <stdio.h>

int main(int argc, char** argv)
{
    int a, b;
    int i, j;
    printf("Low, high numbers:");
    scanf("%d %d", &a, &b);

    printf("      ");
    for(i = a; i <= b; i++) printf("%3d ", i);
    printf("\n     ");
    for(i = 0; i < 4*(b-a + 1); i++) putchar('.');
    putchar('\n');

    for(i = a; i <= b; i++)
    {
        printf("%3d | ", i);
        for(j = a; j <= b; j++)
            printf("%3d ", i*j);
        putchar('\n');
    }

    return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List