Results 1 to 2 of 2
Thread: Help with multiplication table
- 07-09-2007, 08:09 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 114
- Rep Power
- 0
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!"); } } }
Albert:rolleyes:Last edited by Albert; 07-09-2007 at 08:13 PM.
- 07-10-2007, 05:44 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 5
- Rep Power
- 0
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 % 3 == 0)
System.out.println();
}
}
}
Similar Threads
-
Hash Table help
By rhm54 in forum New To JavaReplies: 0Last Post: 02-08-2008, 02:25 AM -
AWT Table Scrolling
By albert_kam in forum AWT / SwingReplies: 0Last Post: 01-03-2008, 12:37 PM -
Help with Multiplication
By phil028 in forum New To JavaReplies: 1Last Post: 12-06-2007, 08:39 PM -
regarding to creating table.....
By daredavil82 in forum New To JavaReplies: 0Last Post: 11-18-2007, 05:55 AM -
Table Help
By CoOlbOyCoOl in forum NetBeansReplies: 1Last Post: 05-06-2007, 05:19 PM
Bookmarks