Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please Help

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please Help

    Alright this is kinda urgent because the program is due in a few hours.

    Here's the instructions:

    Program Description: Write a program that accepts a number of rows between 0 and 9. Produce a multiplication triangle of n rows. For each row contains entries up to it's row size (i.e row 3 will have the values 1X3, 2X3, 3X3, row 4 will have the values 1X4,2X4,3X4,4X4).

    Sample Output:

    Enter # of rows 6
    1 2 3 4 5 6
    1
    2 4
    3 6 9
    4 8 12 16
    5 10 15 20 25
    6 12 18 24 30 36

    Enter # of rows 2
    1 2
    1
    2 4

    Enter # of rows 7
    1 2 3 4 5 6 7
    1
    2 4
    3 6 9
    4 8 12 16
    5 10 15 20 25
    6 12 18 24 30 36
    7 14 21 28 35 42 49

    This is what I have:

    import java.util.Scanner;

    public class Prog166g
    {
    public static void main(String[] args)
    {
    //Set up keyboard
    Scanner keyboard = new Scanner(System.in);

    //Variables
    int input;

    //Input
    System.out.print("Enter # of rows: ");
    input = keyboard.nextInt();

    //Loop to get first row
    for (int counter = 1; counter <= input; counter++)
    {
    System.out.print("\t" + counter);
    }
    System.out.println("");

    //Loop to get everything else
    for (int count = 1; count <= input; count++)
    {
    System.out.println("\t" + count);
    }
    }
    }

    And this is what I'm getting (using 2 as sample input):
    Enter # of rows: 2
    1 2
    1
    2

    Can you please help me?? I've tried everything and I just can't get anything to work.

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    3,446
    My Mood
    Mellow
    Thanks
    86
    Thanked 476 Times in 467 Posts

    Default Re: Please Help

    Please read the Announcement topic at the top of the sub-forum to learn how to post code in code tags plus other useful info for new users.

    Give yourself a chance next time. Hope it worked out for you.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Please Help

    this is my solution. hope it's not to late:
    ...
    Last edited by copeg; December 2nd, 2013 at 08:47 AM. Reason: Removed spoonfed code

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    3,446
    My Mood
    Mellow
    Thanks
    86
    Thanked 476 Times in 467 Posts

    Default Re: Please Help

    @racoonic: Please don't post solutions. That's not what we do here, and it's not helping those requesting help or guidance to become better programmers.