programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

generate an output pattern

chrstian ferma
Ranch Hand
Posts: 72
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

Tim Cooke
Marshal
Posts: 4051
239
• 2

Joanne Neal
Rancher
Posts: 3742
16
• 2
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

fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
• 1
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
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: 4051
239
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.

Winston Gutkowski
Bartender
Posts: 10575
66
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: 10575
66
• 1
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
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
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
my bad not a detailed post , my post looks like im looking on exact answer

Winston Gutkowski
Bartender
Posts: 10575
66
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
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
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

 It is sorta covered in the JavaRanch Style Guide.