• 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

Suggestions on this code needed.

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw a question on "YAHOO ANSWERS" and and here is my solution .I just want to get some suggestions to improve my code .Or if I have used some bad programming practices to get to know about them.but I dont know is it ok to post this kind of questions where actually Im not asking a specific question .So My friends if this is post is not suitable please tell me.I won't post this kind of questions again .Im learning java through self studies these days so finding a way to improve my coding abilities.

Question was ---


How to do this java programme?

Q3. Write a program to draw a diamond sign in to the screen with different heights entered by the user. See following example.

http://answers.yahoo.com/question/index?qid=20090925215708AAkjRKl




and here is my answer
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you run your program?? It doesn't produces the same result as in the question...
 
lakmal padmakumara
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ankit you were dead right !!! actually what had happened was the yahoo page i visited showed the exact output i was trying to get.So as a stupid i didn't read the whole problem,and started coding for the output i saw.(may be an error in loading of that yahoo page )

And after your correction i tried to get that output and here is my code .but there is a error in the shape .I cant point out the error .Please help me on this !!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You posted this question in the forum about the SCJP exam, but this doesn't seem to be directly related to the SCJP. I'll move this to a more appropriate forum for you.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
* Are you aware that you are only using your static variables height
and state in your main method? I'd suggest to have those variables
be local variables in your main method then.
* Add more comments to your code to make it easier to read what, for example,
the goals of your for-loops are. I (and you after X months) have to completely
figure it out myself. Something like:

* After you've done that, you'll quickly find out that you should not have put your
for-loop for variable k (denoted A above) within your for-loop of variable j (denoted B above).

Good luck finishing up
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does your do loop do? It looks as if it will be confusing to use, and you will not actually get an odd number.
Why have you got so much code in the constructor?
 
reply
    Bookmark Topic Watch Topic
  • New Topic