Operators
public class Operators {
public static void main(String[] args) {
int a=5,b=5,c;/* = is an assignment operator.
Other assignment operators are +=,-=,*=,/=,%=,<<=,>>=,&=,^= and |= */
c=a+b;/* + is an arithmetic operator,other arithmetic operators are
-,*,/,%,++ and -- */
System.out.println("Sum of a and b= "+c);
if(c==10){
System.out.println("Use of relational operator");
/* == is a relational assignment operator,
other relational operators are !=,<,>,<= and >= */
}
c=a&b;/* & is a bitwise AND operator.Other bitwise operators are
|,^,~,<<,>> and >>> */
System.out.println("Binary AND value of a and b= "+c);
boolean b1=true,b2=false;
System.out.println("Logical AND value of b1 and b2= "+(b1&&b2));
/* && is a logical AND operator.
Other logical operators are || and ! */
String Vehicle="Car";
String MyVehicle=(Vehicle.equals("Car"))?"Car":"Bike"; // Conditional Operator Example
System.out.println("My Vehicle is "+MyVehicle);
}
}
Output:
Sum of a and b= 10
Use of relational operator
Binary AND value of a and b= 5
Logical AND value of b1 and b2= false
My Vehicle is Car