• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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: 2690
343
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?
 
Master Rancher
Posts: 195
7
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: 7084
491
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.
 
Sheriff
Posts: 24635
56
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.
 
Let nothing stop you! Not even this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!