Arithmetic Operation In Java Example

Chapter: Operators Last Updated: 11-06-2016 19:02:49 UTC

Program:

            /* ............... START ............... */
                
public class JavaArithmeticExample {
	public static void main(String[] args) {
		int x = 10;
		int y = 20;
		int result = x + y;
		System.out.println("x + y = " + result);

		result = x - y;
		System.out.println("x - y = " + result);

		result = x * y;
		System.out.println("x * y = " + result);

		result = y / x;
		System.out.println("y / x = " + result);

		result = x % 3;
		System.out.println("x % 3 = " + result);

	}
}

                /* ............... END ............... */
        

Output

x + y = 30
x - y = -10
x * y = 200
y / x = 2
x % 3 = 1

Notes:

  • The Java programming language provides operators that perform addition, subtraction, multiplication, and division.
  • (+) Unary plus operator; indicates positive value.
  • (-) Unary minus operator; negates an expression.
  • (++) Increment operator; increments a value by 1.
  • (--) Decrement operator; decrements a value by 1.
  • (!) Logical complement operator; inverts the value of a boolean.

Tags

Arithmetic Operation, Java

Similar Programs Chapter Last Updated
Java Left Shift Operator Operators 04-09-2018
Java Addition Operator Operators 18-05-2017
Java Right Shift Operator Operators 13-12-2016
Prefix Operator In Java Example Operators 19-06-2016
Logical Operators In Java Example Operators 17-06-2016
Operator Precedence In Java Examples Operators 17-06-2016
Ternary Operators In Java Example Operators 15-07-2016
Relational Operators In Java Example Operators 11-06-2016
Modulus Operators In Java Example Operators 15-07-2016
Increment And Decrement In Java Example Operators 15-07-2016
Boolean Operator In Java Example Operators 15-07-2016
Bitwise Operator In Java Example Operators 16-06-2017
Assignment Operation In Java Example Operators 06-04-2016

1