Pattern Program help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dio1080
    New Member
    • Sep 2007
    • 5

    Pattern Program help

    Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this:
    123456
    12345
    1234
    123
    12
    1

    but when I try it, it goes like this:
    123456
    12345
    1234
    123
    12
    1

    This is my program:
    public class Patterns{
    public static void main (String [] args) {

    //set up for the rows

    for(int row = 7 ; row > 1; row--){

    for (int num = 1; num < row; num++){

    System.out.prin t(num);
    }
    System.out.prin tln();
    }

    }

    }


    Can anybody help please? thanks
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #2
    Originally posted by Dio1080
    Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this:
    123456
    12345
    1234
    123
    12
    1

    but when I try it, it goes like this:
    123456
    12345
    1234
    123
    12
    1

    This is my program:
    Code:
    public class Patterns{
    public static void main (String [] args) {
     
    //set up for the rows
     
    for(int row = 7 ; row > 1; row--){
     
    for (int num = 1; num < row; num++){
     
    System.out.print(num);
    }
    System.out.println();
    }
     
    }
     
    }
    Can anybody help please? thanks
    Hi,
    Please use code tags while posting code.
    Your desired output and program output is same ... then what is the problem ?

    Comment

    • Dio1080
      New Member
      • Sep 2007
      • 5

      #3
      the right way

      I'm sorry, it must have typed it wrong, this is what I'm looking for:
      123456
      12345
      1234
      123
      12
      1
      Last edited by Dio1080; Sep 27 '07, 04:39 AM. Reason: wrong way

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by Dio1080
        I'm sorry, it must have typed it wrong, this is what I'm looking for:
        123456

        12345

        1234

        123

        12

        1
        Have you written down your algorithm for this first?

        Comment

        • Dio1080
          New Member
          • Sep 2007
          • 5

          #5
          algorithm? I don't think we learned that yet?

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Dio1080
            algorithm? I don't think we learned that yet?
            Originally posted by Merriam Webster
            Main Entry: al·go·rithm
            Pronunciation: 'al-g&-"ri-[th]&m
            Function: noun
            Etymology: alteration of Middle English algorisme, from Old French & Medieval
            Latin; Old French, from Medieval Latin algorismus, from Arabic al-khuwArizmi,
            from al-KhwArizmI fl A.D. 825 Islamic mathematician

            : a procedure for solving a mathematical problem (as of finding the greatest
            common divisor) in a finite number of steps that frequently involves repetition of
            an operation; broadly : a step-by-step procedure for solving a problem or
            accomplishing some end especially by a computer
            kind regards,

            Jos

            Comment

            • Nepomuk
              Recognized Expert Specialist
              • Aug 2007
              • 3111

              #7
              Originally posted by Dio1080
              algorithm? I don't think we learned that yet?
              An algorithm is similar to a recipe - instructions on how to do a job in loads of little steps.
              For example, the algorithm to boil water may be:
              1. Make sure, you have a kitchen (if you don't, create one).
              2. Make sure, you have a pot (if you don't, create one).
              3. Make sure, you have a tap (if you don't, create one).
              4. Make sure, you have a oven (if you don't, create one).
              5. Go into the kitchen (may be complex, depending on your current position).
              6. Get a pot out of the shelves (may be more complex, e.g. if there are doors).
              7. Position the pot under the water tap (you may have to push it to one side before).
              8. Turn the tap on (there are loads of different taps).
              9. While the pot isn't full enough, keep checking, if the pot is full enough (you may want to take a break every time you've checked).
              10. When the pot is full, turn the tap off (same issue as turning it on).
              11. Lift the pot.
              12. Position the pot on the oven.
              13. Switch the oven on (depending on your type of oven, this could work in different ways).
              14. While the water isn't boiling, check if it's boiling.
              I know, that is very detailed, but that's how you have to think when writing a program. A person would understand the command "boil water", but a computer needs all of these steps.

              Greetings,
              Nepomuk

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by nepomuk
                I know, that is very detailed, but that's how you have to think when writing a program. A person would understand the command "boil water", but a computer needs all of these steps.

                Greetings,
                Nepomuk
                Two questions for a mathematician and a physicist

                Question 1:

                There's a bunsen burner, a book of matches a water tap and an empty kettle;
                how to boil water?

                Both the physicist and the mathematician come up with an identical answer:
                open the tap, filll the kettle, close the tap again, put the kettle on the bunsen
                burner, light it using the matches and wait.

                Question 2:

                There's a filled kettle positioned on the bunsen burner; how to boil water?

                The physicist's answer: light the burner and wait.

                The mathematician's answer: empty the kettle; now the problem is reduced to
                the previous question.

                kind regards,

                Jos ;-)

                Comment

                • Nepomuk
                  Recognized Expert Specialist
                  • Aug 2007
                  • 3111

                  #9
                  Originally posted by JosAH
                  Two questions for a mathematician and a physicist

                  Question 1:

                  There's a bunsen burner, a book of matches a water tap and an empty kettle;
                  how to boil water?

                  Both the physicist and the mathematician come up with an identical answer:
                  open the tap, filll the kettle, close the tap again, put the kettle on the bunsen
                  burner, light it using the matches and wait.

                  Question 2:

                  There's a filled kettle positioned on the bunsen burner; how to boil water?

                  The physicist's answer: light the burner and wait.

                  The mathematician's answer: empty the kettle; now the problem is reduced to
                  the previous question.

                  kind regards,

                  Jos ;-)
                  Nice one! ^^

                  Comment

                  • Ganon11
                    Recognized Expert Specialist
                    • Oct 2006
                    • 3651

                    #10
                    ERP! But once the kettle is empty, there's no specific mention of a tap? Where will the mathematician get the water? And besides, there aren't any matches.

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by Ganon11
                      ERP! But once the kettle is empty, there's no specific mention of a tap? Where will the mathematician get the water? And besides, there aren't any matches.
                      Yep, you're right (bloody nitpickers ...) I should've defined both problems in a bit
                      more detail; but I hope you get the idea ;-)

                      kind regards,

                      Jos

                      Comment

                      • Ganon11
                        Recognized Expert Specialist
                        • Oct 2006
                        • 3651

                        #12
                        Originally posted by JosAH
                        (bloody nitpickers ...)
                        Wait, almost 50% of every post I've seen you make is nitpicking - you even admit so yourself on many occasions.

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by Ganon11
                          Wait, almost 50% of every post I've seen you make is nitpicking - you even admit so yourself on many occasions.
                          That wasn't me.

                          kind regards,

                          Loretta ;-)

                          Comment

                          Working...