Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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?
 
Sheriff
Posts: 3113
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus 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?
 
Rancher
Posts: 260
12
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,...)

 
Sheriff
Posts: 7616
522
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: 25594
69
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.
 
It runs on an internal combustion engine. This ad does not:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic