Results 1 to 2 of 2
  1. #1
    relics is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default trouble with loops

    alright guys i am in my first java class and i am a complete newb.

    my problem is a simple one i think. i just need to print a pyramid shaped triangle out of random integers 1-9, and the user input specifying the height.

    this is the section i am having trouble with

    input = keyboard.nextInt();

    for (int i=1; i<=input; i++){

    for (int j=1; j<=i; j++)

    i have this which prints something like this

    X
    XX
    XXX
    i need it to look like this
    X
    XX
    XXX
    XX
    X

    any advice or help would be great

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default

    You have left off the part of your code that prints the output and that makes the decision on how many Xs to print on each line.

    See my post on the other thread: Loop Help

Similar Threads

  1. Help with loops!
    By jrelvi23 in forum New To Java
    Replies: 9
    Last Post: 09-04-2012, 02:36 PM
  2. these loops...
    By Blaedel in forum New To Java
    Replies: 0
    Last Post: 10-01-2009, 07:59 PM
  3. how to use do while loops
    By mikeitalydz in forum New To Java
    Replies: 32
    Last Post: 09-26-2009, 09:30 PM
  4. Replies: 2
    Last Post: 02-23-2009, 03:18 AM
  5. Loops (while do etc)
    By manupr in forum New To Java
    Replies: 1
    Last Post: 01-15-2008, 04:59 AM

Posting Permissions

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