Multplication table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varund
    New Member
    • Jun 2010
    • 2

    Multplication table

    hi,i write a code for multiplication table,it is compiled properly but it is showing run time error.i think there is some problm in declaring array.i cant fix it.plz help me out with this..i am a beginner in java.

    My code is
    class Multiplication
    {

    public static void main (String[] a)
    {
    int num = Integer.parseIn t(a[0]);

    for( int i=1;i<=10;i++)
    System.out.prin tln(i*num);
    }

    }

    Error is :
    Exception in thread "main" java.lang.Array IndexOutOfBound sException: 0 at Multiplication. main(Main.java: 6)
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    How are you running the program?
    I suggest putting a debug statement like:
    System.out.prin tln("The number is "+a[0]);
    as the first line of your main function.

    Normally the first argument is the name of the program.

    Comment

    • varund
      New Member
      • Jun 2010
      • 2

      #3
      Multiplication

      Hello jkmyoung,

      I tried to insert the command,it goes correct while compiling,and the same error repeating me in the run time.
      i am trying to compile the program by javac Multiplication. java and then java Multiplication.

      i cant get it,can u edit the code and tell the procedure,what is the mistake i am doing..

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Ok. Your program is receiving an empty argument list.
        You have to pass in the argument like:
        java Multiplication 100

        I would suggest checking if there is an argument to begin with, eg:
        Code:
          if (a.length < 1){
            System.err.println("Usage: java Multiplication [number]");
            return;
          }
        }

        Comment

        Working...