Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

+ and - are considered unary operators?

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the javacertificate.com test they said + and - are unary operators...how are they used as unary operators, I always thought they were arithmetic only.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see section 15.15.3 and section 15.15.4 of the Java Language Specification.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+ and - can be used both as unary and binary operators. For instance, in the following expression:
- the first + is a binary operator (applies to i and -j)
- the first - is a unary operator (applies to j)
- the second - is a binary operator (applies to -j and +k)
- the second + is a unary operator (applies to k)
i + (-j) - (+k)
Of course, the above expression can be simplified and is equivalent to i - j - k
 
    Bookmark Topic Watch Topic
  • New Topic