• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic