Arithmetic Operators

0

Arithmetic Operators in java.

/*
-------------------- Arithmetic Operators --------------------
Java supports 5 Arithmetic operators
1. Addition (+)
2. Subtraction (-)
3. Multiplication (*)
4. Division (/)
5. Reminder (%)
-------------------- Arithmetic Operators precedence --------------------
*,/,%   operators have highest and same precedence
+,-       operators have next and same and precedence
note: In java all operators in an expression are executed from LEFT to RIGHT means from "=" operator to "," according to their precedence. */

// What is the output from the below program arithmetic statements.

class ArithmeticOperators{
     public static void main(String arg[]){

System.out.println(2+6-2);
System.out.println(2-2+6);
System.out.println(2*2+6);
System.out.println(2*6+2);
System.out.println(4/2*2);
System.out.println(2*6/5);
System.out.println(5*6/2);

System.out.println(5%2);
System.out.println(2%2);
System.out.println(2-2);
System.out.println(2+2);
System.out.println(8/2%2);

System.out.println(2-4+16/2*4%2);
System.out.println(4*2+8/2-3*3+4/2);
System.out.println(4*2+8/2-3*3+6/3);
System.out.println(8+8/2-3*3+6/3);
System.out.println(8+4-3*3+6/3);
System.out.println(12-9+2);
}
     }



Compilation:
G:\> javac ArithmeticOperators.java

Execution:
G:\> java ArithmeticOperators

Out Put:

6
6
10
14
4
2
15
1
0
0
4
0
-2
5
5
5
5
5

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts