What are Arithmetic Operators in java


Arithmetic Operators >


Java arithmetic operators work same as they do in mathematics.
Operator
Description
+
Addition
(can be used for String concatenation also)
-
Subtraction
*
Multiplication
/
Division
%
Modulus/ Remainder



Program 1 to demonstrate Arithmetic operators
/** JavaMadeSoEasy.com */
public class ArithmeticOperatorTest {
   public static void main(String[] args) {
          int x=4;
          int y=2;
          int result=x+y;
          System.out.println("+   "+ result); //6
          result=x-y;
          System.out.println("-   "+ result); //2
          result=x*y;
          System.out.println("*   "+ result); //8
          result=x/y;
          System.out.println("/   "+ result); //2
          result=x%y;
          System.out.println("%   "+ result); //0
         
   }
}
/*OUTPUT
+   6
-   2
*   8
/   2
%   0
*/

No comments:

Post a Comment