# Row and Column input

• 05-20-2013, 09:51 PM
Xavier
Row and Column input
I just made a program that took the user's input and made a multiplication table out of it. It took the integer the user entered and made that amount of rows AND columns. Now i need to be able to get two individual inputs for the amount of columns and the amount of rows and make a multiplication table out of it. this is the code i have for the original multiplication table. please help me out with what to do to make the new one.

import java.util.Scanner;

public class MultiplicationTable {
public static void main(String[] args) {
int j= 0, z = 1, y = 1, p = 0;
System.out.println("Enter the number of rows you want: ");
Scanner scan = new Scanner(System.in);
j = scan.nextInt();
while(z <= j)
{
while (y <= j)
{System.out.print((y * z + "\t"));
y = (y + 1);

}
System.out.println();
z = z + 1;
y = 1;
}}}
• 05-20-2013, 10:09 PM
jim829
Re: Row and Column input
First, you should place your code between code tags [CODE][/CODE] to properly format it. Second, you clearly have the code for a square multiplication table. This was the hard part. How do you think you might go about doing it for arbitrary rows and columns?

Regards,
Jim
• 05-20-2013, 10:22 PM
Xavier
Re: Row and Column input
I'm not really sure what you were expecting a multiplication table to be. Of corse it's going to be square...you clearly didn't bother answering my question. and here you freaking go
Code:

```import java.util.Scanner; public class MultiplicationTable {         public static void main(String[] args) {                 int j= 0, z = 1, y = 1, p = 1;                         System.out.println("Enter the number of rows you want: ");                         Scanner scan = new Scanner(System.in);                         j = scan.nextInt();                         while(z <= j)                         {                                 while (y <= j)                                 {System.out.print((y * z + "\t"));                                 y = (y + 1);                                                                 }                                 System.out.println();                                 z = z + 1;                                 y = 1;                         }}}```
• 05-20-2013, 10:36 PM
Norm
Re: Row and Column input
A suggestion for naming variables: use a name that says what is in the variable. For example: nbrOfRows instead of j.
Later when this code uses more variables, having meaningful names will help everyone understand what the code is doing.
• 05-20-2013, 10:38 PM
jim829
Re: Row and Column input
Nice attitude! Well since a multiplication table can't be anything but square then I guess your question can't be answered.

Good luck!
Jim
• 05-21-2013, 03:33 AM
KevinWorkman
Re: Row and Column input
Quote:

Originally Posted by Xavier
I'm not really sure what you were expecting a multiplication table to be. Of corse it's going to be square...you clearly didn't bother answering my question. and here you freaking go

I highly suggest adjusting your attitude. Jim is helping you, for free, in his spare time. He gave you a hint and asked a simple request which everybody would have asked and which is spelled out in the rules and regulations you were supposed to read before posting.

If you can't take the time to reply in a polite manner, why should we take the time to help you?

In my humble opinion you owe Jim an apology- we understand that you're probably frustrated, but how this works is you ask a question and we help you figure it out by asking you more questions. If you're expecting a spoonfed solution, I suggest you look elsewhere.

Further immature reactions will get you banned.
• 05-30-2013, 06:59 PM
Xavier
Rows and columns
I need to create a multiplication table that takes the number of columns and rows from the user. please help me out

import java.util.Scanner;

public class MultiplicationTable {
public static void main(String[] args) {
int j= 0, z = 1, y = 1, p = 1;
System.out.println("Enter the number of columns you want: ");
Scanner scan = new Scanner(System.in);
j = scan.nextInt();
System.out.println("Enter the number of rows you want: ");
p = scan.nextInt();
while(z <= j)
{
while (y <= j)
{System.out.print((y * z + "\t"));
y = (y + 1);

}
int x = 0;
x = p;
while (p < x){
x = p;
System.out.print(p * z + "/t");
p = p + 1;
y = 1;
}}}}
• 05-30-2013, 07:03 PM
KevinWorkman
Re: Rows and columns
Please use the code tags when posting code.

You haven't asked a question. What does this code do? Does it compile? Does it run? What are you confused about? Where are you stuck?
• 05-30-2013, 07:08 PM
Xavier
Re: Rows and columns
my mistake. so far the code just prints out the number of columns across the top of the multiplication table. i need it to also print the number of rows down the left side of the table and fill in the rest of the numbers. im stuck with the last while statement i believe. thanks for the help!
• 05-30-2013, 07:51 PM
jim829
Re: Rows and columns
I thought I remembered this. Double posted on this forum. http://www.java-forums.org/new-java/...umn-input.html

Jim
• 05-30-2013, 07:56 PM
KevinWorkman
Re: Row and Column input
I've merged the two threads. Just because you didn't like the help you already received doesn't mean you should waste our time by ignoring it and posting another copy of the same question.