Operator in Java Program – 2
Operator is very important for all languages. Operator can calculate, check, assign, increase and decrease the value of variable. So operator is heart of java program. I give simple example of operator in java.
“ans = (x>y) ? x : y;
In this example ans, x and y are variable;
= (assignment) and > (Relational) are operators. “
So we can easily understand the import of operator in java program language. In this blog we will discuss on Relational [ >, <, >=, <=, ==, != ] and Conditional[ (condition) ? true : false ] operators.
>, <, >=, <=, ==,!=are relational operator in all java programming languages. These operators help for check relation on two variables. We are familiar with >, <, >=, <=, ==,!= relational operator in C and Cpp. They are working same as C and Cpp.
This operator is also famous as ternary or three way operator in java program. Using of this operator we can check two or more variable like if we want find maximum number from two numbers. So we can use this operator. Symbol of this operator is [(condition)? true part: false part]. If condition is true that time true part will execute otherwise false part will execute.
Program in Relational Operator ans Conditional Operator:
public static void main(String args)
int x = 67;
int y = 55;
max = (x>y) ? x : y;
System.out.println(“Max = ” + max);
Video available on YouTube.
If you have problem on this blog, you can directly comment or subscribe on website.
Share and Enjoy
490total visits,3visits today