Operators in Java.

In this article,Operators in Java is explained in detail with examples.
Operators in Java are special symbols, which are used to perform mathematical or other types of operations using values/operands in a program.
Ex:
a+b (+ operator)
a,b are values/operands.
Based on the type of operation and number of values used to perform an operation, Java operations/Operations in Java are divided into different types. (From topic Operators in Java) 
  • Arithmetic Operators.
  • Relational Operators.
  • Relational Operators.
  • Logical Operators.
  • Assignment Operators.
  • Unary Operators.
  • Ternary Operators.
  • Bitwise Operators.
  • String addition Operators.
  • Special Operators. 
Arithmetic Operators.
They are also called as binary operators because they take two values to perform the operation.The operations are,                                                           (From topic Operators in Java) 
Symbol
Description
Example
+
Addition
a+b
-
Difference
a-b
*
Product
a*b
/
Division
a/b
%
Modulo
a%b
Ex
//program related to Operators in Java-Arithmetic options.
class BinaryOperations
{
public static void main(String args[])
{
//using integers.
int x=9,y=5;
System.out.println("x is: "+x);
System.out.println("y is: "+y);
System.out.println("x+y is: "+(x+y));
System.out.println("x-y is: "+(x-y));
System.out.println("x*y is: "+(x*y));
System.out.println("x/y is: "+(x/y));
System.out.println("x%y is: "+(x%y));
// using float values.
// use alternate float values for execution by keeping one float as inactive by making them as single line comment (//---).
float x=9.5f,y=2.5f;
float x=10.0f,y=3.0f;
System.out.println("x is: "+x);
System.out.println("y is: "+y);
System.out.println("x+y is: "+(x+y));
System.out.println("x-y is: "+(x-y));
System.out.println("x*y is: "+(x*y));
System.out.println("x/y is: "+(x/y));
System.out.println("x%y is: "+(x%y));
// special cases, when it is compiled it shows run-time error.
int a=10,b=0;
System.out.println("a/b is: "+(a/b));
//floating is acceptable in java
float p=10.5f,q=0.0f;
System.out.println("p/q is"+(p/q));
}
}
Output                                     (From topic Operators in Java) 
Using integer values.
Integer Values-javaform

Using first float values.
First Float Values-javaform

Using Second float values.
Second Float Values-javaform

Using Special case using Int values.
Special Case Using Int Values-javaform

Using Special case using float values.
Special Case using float Values-javaform
                            To get the code file use me.
Note
Special cases.      (From topic Operators in Java) 
Any integer is divided by 0, is not permissible in java. It generates Run time error.
Any floating is divided by 0, is permissible in java. It is Infinity.
when we use division(/) operator, it gives quotient as output.
when we use modulo(%) operator, it gives remainder as output.

Continue to next topic Relational and Logical Operators.

Begin your career in Digital Marketing,What is digital marketing? Digital Marketing online course. It's an current evolving technology which can give support to establish your own startup through Digital Marketing.

Do check my new startup Surprise Planners in HyderabadLavish Surprises our services are surprise party planners in Hyderabad, surprise giftssurprise birthday party planners Hyderabad, Wedding anniversary surprises, surprise planners Hyderabad.

Hi Friends, Please comment down your views in the comment section below. Thank you...

No comments:

Connect with Us by Subscribing here for more Updates..!

* indicates required