• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Suggestions on this code needed.

 
lakmal padmakumara
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 !!!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
John Sutt
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic