• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please look at my code and tell me what I'm doing wrong  RSS feed

 
jason fichter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to turn this into code that will give you the actual problem followed by the answer. // (46.2 divided by 11) minus 3 plus 24 modulus (17 minus 2 times 3)
this is what i have
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my godness! That is long one!
All entries below are clickable links:
TellTheDetails, ItDoesntWorkIsUseless - What do you expect? What happened instead?
DontWriteLongLines - to make your post more readable

Do you have to use Hungarian notation? OK, that's a matter of taste but could you at least have a meaningful names for your variables? It's very hard to read it that way it is.

And welcome to the Ranch!
 
jason fichter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to keep it in the same general format because it is for my class and that is the way the teacher wants it.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. The code would look cleaner and nicer if you:
1. calculated the result before printing it
2. used System.out.printf
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jason fichter wrote:i have to keep it in the same general format because it is for my class and that is the way the teacher wants it.

Well you can tell him from me that it's REALLY bad practise. And regardless of what he wants, we don't like long lines; so if you're posting code here, please follow our rules.

I've broken it up for you as best I can, and it looks wrong to me - but I wouldn't have worked it out the way you wrote it.

I'd also follow Pawel's advice and use printf() or String.format() if I were you.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!