Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Pattern

Pattern

Scheduled Pinned Locked Moved Java
regexhelpquestionlearning
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    V ethi
    wrote on last edited by
    #1

    Hello every one ..emm a beginner in progmming . And I have a problem while printing a asterisks patter pattern is : i have to print the patter as per th user input like {3,2,4} * * * * * * * * * this pattern should be for n inputs.MY problem is after printing a vertical line how could i go back to top to print another line. I have understood that first i have to find the max among all the inputs then have to print the max-input no blank in every vertical line but i dnn knw how can i print vertically :confused:

    L J 2 Replies Last reply
    0
    • V V ethi

      Hello every one ..emm a beginner in progmming . And I have a problem while printing a asterisks patter pattern is : i have to print the patter as per th user input like {3,2,4} * * * * * * * * * this pattern should be for n inputs.MY problem is after printing a vertical line how could i go back to top to print another line. I have understood that first i have to find the max among all the inputs then have to print the max-input no blank in every vertical line but i dnn knw how can i print vertically :confused:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Well the numbers (3,2,4) don't seem to match your pattern anywhere so it is difficult to see the connection between the two. However, in order to print patterns of stars you print rows first. So it is just a matter of using the counts to decide how many to print on each row. If you try figuring out how you would do it using pen and paper, then coverting that to code should be quite easy.

      Veni, vidi, abiit domum

      V 1 Reply Last reply
      0
      • V V ethi

        Hello every one ..emm a beginner in progmming . And I have a problem while printing a asterisks patter pattern is : i have to print the patter as per th user input like {3,2,4} * * * * * * * * * this pattern should be for n inputs.MY problem is after printing a vertical line how could i go back to top to print another line. I have understood that first i have to find the max among all the inputs then have to print the max-input no blank in every vertical line but i dnn knw how can i print vertically :confused:

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        If I understand you post your 'algorithm' is incorrect. You do not print vertically - Instead you print horizontally. Hopefully you have already learned about loops and arrays. So 1. Put the values in an array 2. Write a method that finds the maximum value in the array. When if finds it set the array location to -1 (this is how you 'remove' it.) 3. Write a method that takes a X value and prints that many stars. 4. Put 2 and 3 together to print all the rows. 5. Think about how you know it will end (the '-1' is a hint.)

        V 1 Reply Last reply
        0
        • L Lost User

          Well the numbers (3,2,4) don't seem to match your pattern anywhere so it is difficult to see the connection between the two. However, in order to print patterns of stars you print rows first. So it is just a matter of using the counts to decide how many to print on each row. If you try figuring out how you would do it using pen and paper, then coverting that to code should be quite easy.

          Veni, vidi, abiit domum

          V Offline
          V Offline
          V ethi
          wrote on last edited by
          #4

          opp!!! that was my typing mistake first i want to print the 3 stars then 2 and then 4 means basically depending upon the oder of input given by user ..

          L 1 Reply Last reply
          0
          • J jschell

            If I understand you post your 'algorithm' is incorrect. You do not print vertically - Instead you print horizontally. Hopefully you have already learned about loops and arrays. So 1. Put the values in an array 2. Write a method that finds the maximum value in the array. When if finds it set the array location to -1 (this is how you 'remove' it.) 3. Write a method that takes a X value and prints that many stars. 4. Put 2 and 3 together to print all the rows. 5. Think about how you know it will end (the '-1' is a hint.)

            V Offline
            V Offline
            V ethi
            wrote on last edited by
            #5

            yeah i have read about loops and array.i can also find the max among all the elements of an array but what are you saying about location and all couldn't understand... :((

            1 Reply Last reply
            0
            • V V ethi

              opp!!! that was my typing mistake first i want to print the 3 stars then 2 and then 4 means basically depending upon the oder of input given by user ..

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              So what is the problem? Just use each number to create a loop and print that number of stars.

              Veni, vidi, abiit domum

              V 1 Reply Last reply
              0
              • L Lost User

                So what is the problem? Just use each number to create a loop and print that number of stars.

                Veni, vidi, abiit domum

                V Offline
                V Offline
                V ethi
                wrote on last edited by
                #7

                i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??

                L C 2 Replies Last reply
                0
                • V V ethi

                  i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You need to save these numbers in an array which you then use to calculate how many stars to print across each line. It's just a question of a bit of logic and mathematics.

                  Veni, vidi, abiit domum

                  1 Reply Last reply
                  0
                  • V V ethi

                    i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??

                    C Offline
                    C Offline
                    chronodekar
                    wrote on last edited by
                    #9

                    Try changing your approach to the problem. Let's try this. Input : 2, 4, 3 Desired output:

                    *
                    **
                    ***
                    ***

                    For graphical purposes let me remake the output as follows

                    *OO
                    **O
                    ***
                    ***

                    Replace the "O" with spaces. Does it help? -chronodekar

                    L 1 Reply Last reply
                    0
                    • C chronodekar

                      Try changing your approach to the problem. Let's try this. Input : 2, 4, 3 Desired output:

                      *
                      **
                      ***
                      ***

                      For graphical purposes let me remake the output as follows

                      *OO
                      **O
                      ***
                      ***

                      Replace the "O" with spaces. Does it help? -chronodekar

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      How exactly does that help?

                      C 1 Reply Last reply
                      0
                      • L Lost User

                        How exactly does that help?

                        C Offline
                        C Offline
                        chronodekar
                        wrote on last edited by
                        #11

                        There might be a more efficient way of doing it, but here's my thinking. 1. Arrange all the numbers in descending order. Make note of the largest one ( = A). Also store the numbers in an array ( = ARRAY) 2. Count the number of inputs ( = B). 3. Visualize the output in the form of a rectangle - you need to draw (with ASCII) a rectangle whose height is A and width B. Alternatively, you need to print A no. of lines with B characters. Now we come to implementation. In pseudo-code;

                        for (i = A ; i>0; i--)
                        {
                        for (j = 0; j i)
                        print("*");
                        else
                        print("O");
                        }
                        print("\n");
                        }

                        I think that should do it. Any edge case I missed? -chronodekar

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups