Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default Help with multiplication table

    Hi all, I am trying to create a multiplication table. Basically the program will work like this.
    The user will enter a number from 1-9. The output will show a multiplication table. If the user enter 0, then the program will stop and exit.

    Example:
    Enter selection number : 3
    Multiplication table for 3
    3 6 9
    12 15 18
    21 24 27
    Enter selection number : 0
    Exit Program.

    I have done the coding but couldn't get the desired output. Will appreciate if anyone can rectify or point my mistakes and get the program to run as intended. Here is the cosing that I have done :

    Java Code:
    import java.util.Scanner;
    
    public class MultiTable
    {
    
    public static void main (String [] arg)
    {
    Scanner input = new Scanner(System.in);
    
    
    System.out.println("** Welcome to Multiplication Table **");
    
    int n1;
    
    
    System.out.println("\nEnter selection number:");
    n1 = input.nextInt();
    
    {
    
    if(n1!=0)
    
    {
    System.out.println("Multiplication Table for " + n1);
    
    int store[] = new int[9];
    
    for (int i=0; i<store.length; i++)
    {
    store[i] = i;
    }
    
    }
    
    else
    System.out.println("\nExit Program! \nThank You for using me!");
    }
    }
    
    }
    Thanks
    Albert:rolleyes:
    Last edited by Albert; 07-09-2007 at 08:13 PM.

  2. #2
    olatunbode is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    This should do it:

    import java.util.Scanner;

    public class MultiTable
    {
    public static void main (String [] arg)
    {
    Scanner input = new Scanner(System.in);
    System.out.println("** Welcome to Multiplication Table **");

    int n1;
    int store[] = new int[9];

    System.out.println("\nEnter selection number:");
    n1 = input.nextInt();

    if(n1!=0)
    {
    System.out.println("Multiplication Table for " + n1);

    for (int i=0; i<store.length; i++)
    {
    store[i] = i;
    store[i] *= n1;
    }

    }

    else
    System.out.println("\nExit Program! \nThank You for using me!");

    for(int i = 1; i <= 8; i++){
    System.out.print(store[i] + " ");
    if(i &#37; 3 == 0)
    System.out.println();
    }
    }

    }

Similar Threads

  1. Hash Table help
    By rhm54 in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 02:25 AM
  2. AWT Table Scrolling
    By albert_kam in forum AWT / Swing
    Replies: 0
    Last Post: 01-03-2008, 12:37 PM
  3. Help with Multiplication
    By phil028 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 08:39 PM
  4. regarding to creating table.....
    By daredavil82 in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 05:55 AM
  5. Table Help
    By CoOlbOyCoOl in forum NetBeans
    Replies: 1
    Last Post: 05-06-2007, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •