Results 1 to 11 of 11
Like Tree2Likes
  • 1 Post By jim829
  • 1 Post By KevinWorkman

Thread: Row and Column input

  1. #1
    Xavier is offline Member
    Join Date
    May 2013
    Posts
    7
    Rep Power
    0

    Default 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;
    }}}

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,949
    Rep Power
    4

    Default 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
    DarrylBurke likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Xavier is offline Member
    Join Date
    May 2013
    Posts
    7
    Rep Power
    0

    Default 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
    Java 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;
    			}}}

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,607
    Rep Power
    23

    Default 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.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,949
    Rep Power
    4

    Default 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
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,701
    Rep Power
    8

    Default Re: Row and Column input

    Quote Originally Posted by Xavier View Post
    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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Xavier is offline Member
    Join Date
    May 2013
    Posts
    7
    Rep Power
    0

    Default 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;
    }}}}

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,701
    Rep Power
    8

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Xavier is offline Member
    Join Date
    May 2013
    Posts
    7
    Rep Power
    0

    Default 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!

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,949
    Rep Power
    4

    Default Re: Rows and columns

    I thought I remembered this. Double posted on this forum. Row and Column input

    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  11. #11
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,701
    Rep Power
    8

    Default 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.

    I suggest you reply to the helpful questions you've already been asked.
    DarrylBurke likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 0
    Last Post: 01-17-2013, 12:43 PM
  2. insert row and column and delete row and column
    By daredavil82 in forum New To Java
    Replies: 13
    Last Post: 09-22-2011, 06:10 PM
  3. Replies: 9
    Last Post: 02-15-2011, 01:13 AM
  4. Replies: 1
    Last Post: 07-19-2010, 12:31 AM
  5. Replies: 1
    Last Post: 07-06-2010, 04:50 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
  •