You are here: Home / Topics / Arithmetic Operators Examples In Java

# Arithmetic Operators Examples In Java

Filed under: Java on 2023-08-11 19:23:00
`// Arithmetic Operator Exampleclass ArithOpr{public static void main( String args[ ] ){ int a = 25, b = 10; float c = 25.5f, d = 4.0f; System.out.println( " a = " + a ); System.out.println( " b = " + b ); System.out.println( " c = " + c ); System.out.println( " d = " + d );  System.out.println( " a + b = " + ( a + b ) ); System.out.println( " a - b = " + ( a - b ) ); System.out.println( " a * b = " + ( a * b ) ); System.out.println( " a / b = " + ( a / b ) ); System.out.println( " a % b = " + ( a % b ) ); System.out.println( " a + c = " + ( a + c ) ); System.out.println( " c + d = " + ( d + d ) ); System.out.println( " c % d = " + ( c % d ) ); System.out.println( " -a % b = " + ( -a % b ) ); System.out.println( " -a % -b = " + ( -a % -b ) ); System.out.println( " a % b = " + ( a % b ) ); System.out.println( " a % -b = " + ( a % -b ) );}}Output:a = 25b = 10c = 25.5d = 4.0a + b = 35a - b = 15a * b = 250a / b = 2a % b = 5a + c = 50.5c + d = 8.0c % d = 1.5-a % b = -5-a % -b = -5a % b = 5a % -b = 5`