This week's book giveaway is in the Other Languages forum.We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
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:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Liutauras Vilda
• Jeanne Boyarsky
Sheriffs:
• Junilu Lacar
• Rob Spoor
• Paul Clapham
Saloon Keepers:
• Tim Holloway
• Tim Moores
• Jesse Silverman
• Stephan van Hulst
• Carey Brown
Bartenders:
• Al Hobbs
• Piet Souris
• Frits Walraven

# increasing and decreasing in loop

Ranch Hand
Posts: 30
• Number of slices to send:
Optional 'thank-you' note:
I want someone to explain when to use ++x, --x, ++y, --y in for loop with examples and codes.

Secondly, look at this code :

class Uber{
static int y = 2;
Uber(int x) {this(); y = y*2;}
Uber() {y++; }
}
class Minor extends Uber{
Minor() {super(y); y = y+3; }
public static void main (String[] args) {
new Minor();
System.out.println(y);
}}
The answer given in the book of Kathy and Bert is 9.But, i think the answer should be 7. Because,y = 2 and y*2 is 4. With increment of 3 plus 4 i.e y+3(3+4) =7

Sheriff
Posts: 11343
• Number of slices to send:
Optional 'thank-you' note:

Originally posted by Lao Kinsuyi:
...The answer given in the book of Kathy and Bert is 9.But, i think the answer should be 7. Because,y = 2...

But the first line of Uber(int) is this(), which calls Uber() to increment y to 3.

Try adding println statements to see what's happening...

 You showed up just in time for the waffles! And this tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton