• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Code review?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you check this code? What doe sthis output?
 
Saloon Keeper
Posts: 2613
329
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!  

Have you tried compiling and running the code yourself?  What did you find?
 
Ranch Foreman
Posts: 34
1
IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good way is also to try and read your code.

The first thing you have to check is: Imagine you are the compiler. Is the code legal, will it compile? Or are there any errors that will prevent this?

The second thing is reading the code and keep track of the variables during the different iterations (i.e. what is the value of i,...)

 
Marshal
Posts: 6848
470
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krish, welcome to the Ranch.

Please note, we do have a "Code Reviews" forum, to which I've added your topic as opposed to "Java in General", which is meant to be reserved for some advanced topics of Java.
 
Marshal
Posts: 24587
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Brecht Geeraerts wrote:A good way is also to try and read your code.



For me that would be my last choice. If I didn't have access to a Java compiler and somebody demanded for me to do that, then I would reluctantly do it. But that code has features which seem to be designed to have off-by-one errors which I would have to think hard about. And why think hard when you can just run the code and see what it does? Programmers should be lazy, after all.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!