• 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

increment operators

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I fail to understand the 2 + signs before k in 1.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can very well remove one of the +.. It is there to confuse us.. and simply means that k is positive.

You can change it to the following to see the difference
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi angeela
i am totally agree with silpi , its only to cofuse , + + or even hundred + means the same one + . Here first + for addition and second + for sign notation


code:

public class TestClass
{
public static void main (String args[ ] )
{
int k = 1;
int i = ++k + k++ + + k ;
System.out.print(i+ " "+ k) ;
}
}
/*
++k = 1 + 1 =2
k++ = 2+1=3
+k = +3


i = ++k(2) + k++(2) + +k(3);
i = 2 + 2 + 3 = 7
*/



The solution might be confusing.If is there any mistake then please tell me . cia
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic