• Post Reply Bookmark Topic Watch Topic
  • New Topic

value of x?  RSS feed

 
Supriya Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know that how come value of x in the output of the following program is not -1 but 0.




OUTPUT:

02
14
26
48

[Edit - added code tags - see UseCodeTags for details]

 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Supriya. Welcome to The Ranch!

Why do you think it should be -1? Where do you think it gets set to -1.

What I'd suggest is drawing up a little table like this:

Step through the code by hand, writing down the values of x and y when they change, and the output at each print statement. Try that, and if you still don't see why that's the output let us know.
 
Piotr Majcher
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Supriya.

Your code has part witch is never reached.


is the same as


Now your code looks more clearly, so maybe it will be easier to step through your code by hand as Matthew wrote.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piotr Majcher wrote:Hi Supriya.

Your code has part witch is never reached.


Please don't just hand over the answers. We want to encourage the OP to solve his own problem, with a nudge in the right direction here or there as needed. Thanks!
 
Piotr Majcher
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Piotr Majcher wrote:Hi Supriya.

Your code has part witch is never reached.


Please don't just hand over the answers. We want to encourage the OP to solve his own problem, with a nudge in the right direction here or there as needed. Thanks!

No problemo I'm newbie here, and this is good advice for me to be good forum user in the future. Thanks.
 
Supriya Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You.Now i understood.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!