• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

value of x?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]

 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You.Now i understood.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic