in Technology by
What is Unary Operators in Java?

1 Answer

0 votes
by

In Java, the unary operator is an operator that can be used only with an operand. It is used to represent the positive or negative value, increment/decrement the value by 1, and complement a Boolean value. In this section, we will discuss the unary operator in Java with examples and also understand the differences between i++ and i+=1.

Unary Operators in Java

There are five unary operators in Java:

  • Unary Plus
  • Unary Minus
  • Increment Operator
  • Decrement Operator
  • Logical Complement Operator

The following table describes the short description of the unary operators.

Operator Name Symbol Description Example Equivalent Expression
Unary Plus + It is used to represent the positive value. +a a
Unary Minus - It is used to represent the negative value. -a -
Increment Operator ++ It increments the value of a variable by 1. ++a
or
a++
a=a+1
Decrement Operator -- It decrements the value of a variable by 1. --a
or
a--
a=a-1
Logical Complement Operator ! It inverts the value of a boolean variable. !true -

Related questions

0 votes
    The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is ... for unary +: 'str' Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Which is a unary operation: (a) Selection operation (b) Primitive operation (c) Projection operation (d) ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which of these operators is used to allocate memory to array variable in Java? (a) malloc (b) ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What arithmetic operators cannot be used with strings in Python? a) * b) – c) + d) All of the mentioned...
asked Jan 2, 2023 in Technology by JackTerrance
0 votes
    What is Indirection and Increment/Decrement operators with a pointer in C?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    How many operators are there under the category of ternary operators?...
asked Jan 18, 2021 in Technology by JackTerrance
+1 vote
    How many operators are there under the category of ternary operators in C Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    Explain about the SAP ABAP - Operators?...
asked Oct 18, 2020 in Technology by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    Which of the following operators is used to generate instance of an exception which can be thrown using throw? (a ... Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    What are the data types in R on which binary operators can be applied? (a) Scalars (b) Matrices (c) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    ________ provides needed string operators in R. (a) str (b) forecast (c) stringr (d) sqldf I got this ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
...