A Unary, a Binary and a Ternary Operator.

Q1. Distinguish between a unary, a binary and a ternary operator. Give examples of Java operators for each one of them.

Ans. A unary operator requires a single operand. Unary +, unary -, ++, — etc. are some unary operators in Java.

A binary operator requires two operands.

+ (add), – ( subtract), *,  /, % etc. are some binary operators in Java.

A ternary operator requires three operands. ? : (the conditional operator) is a ternary operator in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: