• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

generate an output pattern

 
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program that will display a pattern depending on n. Assume n as a one digit odd number.

Example: if n=9, display
*000*000*
0*00*00*0
00*0*0*00
000***000
 
Marshal
Posts: 6216
502
IntelliJ IDE Python TypeScript Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How's about this? I believe it satisfies your requirements.
 
Rancher
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:I believe it satisfies your requirements.


Not quite I don't think. If the pattern depends on n, it suggests the pattern will be different for different values of n, so I think the code should be
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
an example is great, but it isn't a spec. what EXACTLY should happen for various values of n?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On a more serious note
@chrstian Nobody is going to write the code for you (see NotACodeMill), but if you come up with a more detailed specification* we will certainly try to help you write the code.

* For example
How does that pattern relate to the value 9 ?
What are the patterns for other values of n ?
Is there an algorithm for working out the pattern given a value of n or are they just random patterns assigned to each value ?
 
Tim Cooke
Marshal
Posts: 6216
502
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Joanne, I think we are both correct. The behaviour for when n does not equal 9 is undefined so both of our solutions could be argued to be correct.

However, before we get off an a tangent, I threw in that somewhat glib response to highlight the fact that you have not specified your problem enough to be able to write a complete solution for it. A point that Fred has made in a more straightforward manner.

Another point to not is that we are NotACodeMill, which means that nobody is going to give you the solution. What we will do is help and guide you into solving the problem yourself. That's how we learn.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joanne Neal wrote:* For example
How does that pattern relate to the value 9 ?


That's what I was trying to work out.

As far as I could see, each pattern is 9 characters long, and is made up of 6 '0's and 3 '*'s; but since 9 is the ONLY single-digit odd number that isn't prime, it doesn't seem to give much of a clue.

Winston
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:I threw in that somewhat glib response to highlight the fact that you have not specified your problem enough to be able to write a complete solution for it.


I certainly agree with your point, but it's actually kind of a neat challenge if you take it as one of those "intelligence test" questions.

My observations:
1. All patterns involve '*' and '0'.
2. All patterns are mirror images about a central '*'.
3. All patterns involve exactly one '*' in their "halves".
4. In order, they move from '*' on the outside, to '*' nearest the centre.

So my solution for n=7 would be:
"*00*00*"
"0*0*0*0"
"00***00"

and for n=5:
"*0*0*"
"0***0"

for n=3:
"***"

and if n=1 has a solution:
"*"

Anyone have a different solution?

Winston
 
chrstian ferma
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chrstian ferma wrote:Write a program that will display a pattern depending on n. Assume n as a one digit odd number.



Example: if n=9, display
*000*000*
0*00*00*0
00*0*0*00
000***000



cause i cant understant how the pattern generated , i believe this one can easily done by for loop thank you , i appreciate the answers i believe n=9 then system.out the expected output is not what im trying to explain but it's a valid answer due to not detailed question
 
chrstian ferma
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

Joanne Neal wrote:* For example
How does that pattern relate to the value 9 ?


That's what I was trying to work out.

As far as I could see, each pattern is 9 characters long, and is made up of 6 '0's and 3 '*'s; but since 9 is the ONLY single-digit odd number that isn't prime, it doesn't seem to give much of a clue.

Winston



thank you what im looking is a guidance not the exact answer
 
chrstian ferma
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my bad not a detailed post , my post looks like im looking on exact answer
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chrstian ferma wrote:cause i cant understant how the pattern generated...


Well I'm afraid that's an absolute must. All I've been doing is musing about possibilities.

If this is for a class, then I suggest you ask your tutor, because what you've given us is definitely not enough to go on.

Winston
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chrstian ferma wrote:cause i cant understant how the pattern generated


In that case it's not a Java problem, it's a logic problem.
And if that's all the information you have, then Winston's guess is as good as anyone else's. But for that matter, so is Tim's.
 
chrstian ferma
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

chrstian ferma wrote:cause i cant understant how the pattern generated...


Well I'm afraid that's an absolute must. All I've been doing is musing about possibilities.

If this is for a class, then I suggest you ask your tutor, because what you've given us is definitely not enough to go on.

Winston





thanks i believe i need more details regarding this
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic