Java Help

Discussion in 'General Discussion' started by M.C.E, Nov 17, 2004.

Users Viewing Thread (Users: 0, Guests: 0)

  1. M.C.E

    M.C.E 1981-2013

    Joined:
    Apr 16, 2002
    Messages:
    13,850
    Likes Received:
    6
    Location:
    Cullercoats
    Tecky geeks ;)
  2. 1615634792921.png
  3. Guest

    i HATE java..... :evil: :evil:
  4. WhoIsJohnBenson

    WhoIsJohnBenson Registered User

    Joined:
    Jun 14, 2003
    Messages:
    972
    Likes Received:
    0
    Location:
    kennels
    hmm doesn't look anything wrong with it to me, i'll run it on my machine...
  5. WhoIsJohnBenson

    WhoIsJohnBenson Registered User

    Joined:
    Jun 14, 2003
    Messages:
    972
    Likes Received:
    0
    Location:
    kennels
    well its working fine for me :up:
  6. trance_fan

    trance_fan Registered User

    Joined:
    Nov 7, 2002
    Messages:
    9,022
    Likes Received:
    0
    What is it that you do not understand?

    The ordering of the numbers specifically, or the whole thing?

    Do you understand the for loop etc?

    I presume you will do like.

    What it seems to be:

    // 1 for each row in the pyramid
    for (int row = 1; row <= NUM_OF_LINES; row++)

    Creates the rows - NUM_OF_LINES is initialised with a value of 5, so the program will go round the loop 5 times, thus producing 5 lines.

    // 1.1 print leading spaces
    for (int col = 1; col <= NUM_OF_LINES -row; col++)
    System.out.print(" ");

    this appears to make the spaces so that the output of numbers will actually appear as a pyramid.

    Then for the leading and ending numbers:

    // 1.2 print leading numbers
    for (int num = row; num >= 1; num--)
    System.out.print(num);

    // 1.3 print ending numbers
    for (int num = 2; num <= row; num++)
    System.out.print(num);

    when the number = row, to number >=1, the number will count down.

    Then when the number = 2, to when the num <= row, the numbers increment.

    eg on line 2 - thats row 2, therefore will start with 2, then go to 1. This ends the first loop, and the program moves on to the next loop, and counts up until the number of the row corresponds to the highest number in that particular row.

    Therefore.

    On row 1, there can only be 1 number, on row 2, it will be 212, and so on.

    I only do C++ but the logical flow is the same.

    Hope thats been of some help

Share This Page