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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s