In this example we will see how we can make use of the unary operator. In java we have been provided the unary operators so we should know how to make use of those operators. Unary operators are:
++expr, --expr, +expr, -expr, ~, !
Description of program:
In this section we will know how to make use of the unary operators in java. First all of, we have to define a class "UnaryOperation" . Inside this class we have defined one class variable. We are making one overloaded main method which takes one integer type argument. Define one method operate() of type int where we are going to use the various unary operators. At last inside the main method call the method operate() so that the result can be displayed to the user. The output will be displayed on the screen by using the println() method of the System class.
Here is the code of this program
class UnaryOperation {
|
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: The Unary Operators
Post your Comment