• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

pyramid of numbers

 
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
If 4023 I pass then I should see output like

     0
    2 2
  3  3 3
4  4 4  4
 
Marshal
Posts: 79422
377
  • Number of slices to send:
    Optional 'thank-you' note:
So there is no relationship between the numbers and how many times they are displayed?
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
No
 
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:No


Of course there is. It's just not "display a digit as many times as its value."
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
First digit(i.e least digit) one time in first row
second digit(i.e next least digit) two times in two row
third digit(i.e next least digit) one time in three row

etc
 
Saloon Keeper
Posts: 10797
86
  • Number of slices to send:
    Optional 'thank-you' note:
I normally don't post answers but I feel this thread has gone on way too long.

 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
i will try. thank you
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
below code produced below output


Input number: 5319
  5
 3 3
1 1 1
9 9 9 9




If i want below output as ascending order from first to second row to third row etc as below how to modify the code


Input number: 5319
  1
 3 3
5 5 5
9 9 9 9
 
Carey Brown
Saloon Keeper
Posts: 10797
86
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

Try copying the code correctly.



can you please elaborate on this? I was not clear
 
author
Posts: 23951
142
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:
If i want below output as ascending order from first to second row to third row etc as below how to modify the code



Well, obviously, you need to sort the input first.  Since this is likely a homework assignment, or following up a homework assignment for learning purposes -- what have you done so far to modify it?

Henry
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

Since this is likely a homework assignment, or following up a homework assignment



this is not. you assumption is wrong
 
Henry Wong
author
Posts: 23951
142
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:

Since this is likely a homework assignment, or following up a homework assignment



this is not. you assumption is wrong



The impetus of the assumption is that you are doing this to learn.  Hence, my question of asking what have you done so far.

Now surely, this is not wrong?

Henry
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
Let me try with collection class and let you know about sorting as well
 
Campbell Ritchie
Marshal
Posts: 79422
377
  • Number of slices to send:
    Optional 'thank-you' note:
Why not post something which you wrote yourself that actually works. Never mind how well it works, just something that works. If you have something which works, however badly, you can improve it.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

Why not post something which you wrote yourself that actually works.



i posted more than 50 comments with whatever i can. I do not know something that actually works. If i know would not have posted this question here. can you please provide solution. I am almost about to give up on this challenge
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:


i finally got my solution of ascending pyramid.
how to improve/modify my code. please advise
 
Campbell Ritchie
Marshal
Posts: 79422
377
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:. . . how to improve/modify my code. please advise

Start by indenting it correctly.
Remove all those commented‑out lines.
Remove all those blank lines.
Change the main method to its ideal length: one statement.
Try some object‑oriented programming: you shou‍ld be able to write
new DiamondPrinter(12).print();
and get a diamond printed. (Or maybe only a pyramid).
What do the loops on lines 42‑49 mean? Why are you using <= rather than <?

Is that enough to get you started.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
i will fix them. why eclipse wont remove blank lines when i say control A then Control Shift F to format?
 
Sheriff
Posts: 7125
184
  • Number of slices to send:
    Optional 'thank-you' note:
It will, you just have to tell it what to do.  The default is that multiple existing blank lines collapse to one.  You can change that in:

Windows -> Preferences -> Code -> Formatter

Edit the active profile or create a new one, then click on the Blank Lines tab.
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
You shouldn't remove all the blank lines. A blank line to separate one method from the next or different logical sections of a block of code can improve readability. You don't want to have your code all mashed up into one big continuous blob with no visual cues as to which lines of code belong together.
 
Campbell Ritchie
Marshal
Posts: 79422
377
  • Number of slices to send:
    Optional 'thank-you' note:

Junilu Lacar wrote:. . . A blank line to separate one method from the next . . .

. . . which you can set up as an option in Eclipse.
 
Marshal
Posts: 8880
638
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:why eclipse wont remove blank lines when i say control A then Control Shift F to format?

Don't be lazy. You have around 25 effective lines of code. At this stage probably better would be not to use Eclipse at all, but rather have some text editor and console next to you, so you could compile and run the code from there.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:


does above looks ok?
if i chanfge <= with < first element cut in console output which i do not want.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
I am going through below link

http://www.pmsas.pr.gov.br/wp-content/?id=coderanch-1z0-809&exam=wiki/660020/Main-Pain

i feel it is too much for a simple class



i wonder who (client)  and where CashRegisterLauncher getting called?
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:


i also commented one unsed import which actually i can delete as well in this case
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
Your main() method looks a little better but there's still a lot you can do to improve your code.

1. Why does your print() method return an array of integers which the main() method doesn't even use? What's the point and the logic of doing that?

2. Something like PyramidPrinter would probably be a more suitable name for your class. Class names should be nouns or noun phrases.

3. Your print() method still has too many lines and has the details for doing way too many things.  If a method is going to have detailed implementation in it, let it be for just one simple and focused task. If it does many different things, the method would be better written as a Composed method.
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
Rather than going back to square one and repeating ALL the advice you've been given before over several weeks spanning 2016 and 2017, why don't you go back over this entire thread again and actually read and follow some of the advice you've been given?
 
Liutauras Vilda
Marshal
Posts: 8880
638
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:does above looks ok?

Nice code formatting, have a cow
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

have a cow


where?
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:


i changed the class name. I wonder what you mean by point 1 where main does not even know about int?

my intention is to just print pyramid of numbers and i felt there is no need for main method to know about it. No other business logic or thought process behind that
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

3. Your print() method still has too many lines and has the details for doing way too many things.



if i do away to multiple methods later on orchestration becoming difficult to me. can you please show exactly what you mean by this with working code as i already solved this challenge?
 
Campbell Ritchie
Marshal
Posts: 79422
377
  • Number of slices to send:
    Optional 'thank-you' note:

sai rama krishna wrote:. . . where?

Look above the text of one of your posts. Just right of where it says, “Posted 67 years ago” or similar.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:

Have you read what Junilu wrote 2 posts ago? I really believed you'll absorb that information. Basically how I understood what he said, that you should take very small steps at a time and make some methods, so each of them would do very concrete singular task.


same thing i am trying in last 100 coments. I finally got solution. But now i do not know how to modify my code to look more like object oriented code with bunch of methods as i do not know how to interact printing spaces and printing numbers methods both similtaneously to print the pyramid structure i am interested?
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
Ok, fine. You have been doggedly looking for illumination on this problem and this thread has gone on far too long.

I'll demonstrate to you my process. Keep in mind that there are many ways you can solve this problem. The one I first came up with many posts ago was not even object-oriented; I had all static methods. The reason I did that was because this was only one class and there didn't seem to be a compelling reason for me to create an OO design when there was just one class involved and the process was pretty much sequential. On the other hand, it might be educational to try to do it with a proper object instead of just a bunch of static methods. So, I step through an entirely new solution, using proper objects.

First of all, I see no need to convert to integers as you have been doing. The input is a String and the user is expected to include only digits so I'll make the assumption that that is exactly what the user will do.

So, the first cut will be:

I'll compile this to make sure I have no errors so far. I see that it compiles with no errors, so I continue.

Edit: The code posted above actually does have an error but it's a pretty quick fix. I'll leave it as originally posted anyway.
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
Next, I want to solve the problem of breaking apart the String into separate characters that I can deal with individually. So I'll add some code to do that:

Now, I need a way to verify that I've done the right thing. Normally, I'd write a unit test but this time, I'll just eyeball the result by printing out the characters. I'll add a call to a method that will display something, then add that method:

I see that there are no compiler errors so I run the program and eyeball the result. My run looks looks something like this:

Enter a sequence of digits, no spaces: 3402
3
4
0
2

Ok, now I've made a little bit of progress. That's good.
 
Junilu Lacar
Sheriff
Posts: 17652
300
  • Number of slices to send:
    Optional 'thank-you' note:
So I've run the program twice now and I've had to enter the sequence of digits manually. I miss my automated unit tests. I still don't want to go to the trouble of doing a JUnit right now, especially since I'll have to go and explain it to you and you'll probably have an exponential number of questions to follow. So I'll do the next best thing: I'll hard code my input data for now.  I go back to the getUserInput() method and modify it:

Now I won't have to type in anything and I'll have the same data to work with while I fill out the program.

I run the program again to make sure I didn't mess anything up. It still runs fine.
 
sai rama krishna
Ranch Hand
Posts: 959
2
  • Number of slices to send:
    Optional 'thank-you' note:
makes more sense now. But how to get pyramid structure like
If 4023 I pass then I should see output like

     0
    2 2
  3  3 3
4  4 4  4

that is where all the complexity using multiple methods using OOP and OOD principles?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |