Jump to content

Multiplication tables

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
A quick multiplication table script I came up with after reading about using 2-dimensional arrays.

The user inputs two numbers on the command line, and the program generates a 2-dimensional array of a multiplication table.


import java.util.*;

/**

 *

 * @author James

 */

public class multiplication {

    public static void main(String[] args) {

        Scanner sin = new Scanner(System.in);

        int nNum1, nNum2;

        // this becomes the number of rows

        System.out.print("Enter a number: ");

        nNum1 = sin.nextInt();

        // this becomes the number of cols

        System.out.print("Enter another number: ");

        nNum2 = sin.nextInt();

        

        System.out.println("Here you go a " + nNum1 + " by " + nNum2 +

                " multiplication table.");

        // this array holds a nNum1 * nNum2 multiplication table

        double[][] ardMult = new double[nNum1][nNum2]; 

        

        for (int row=0;row<nNum1;row++) {

            for (int col=0;col<nNum2;col++) {

                ardMult[row][col] = row+1 * col+1;

                System.out.print(ardMult[row][col] + " ");

            }

            System.out.println();

        }

    }


}



#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
That code made no sense to me at all LOL!! But I will test it soon, after I get some programing done :D
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!