English

Explain the following operator with an example program: Arithmetic Operator

Advertisements

Question

Explain the following operator with an example program:

Arithmetic Operator
 
Code Writing
Explain
Advertisements

Solution

An Arithmetic Operator in Java is used to perform mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/) and modulus (%) on numeric values.

Example:

 
class ArithmeticOperator
{
    public static void main(String[] args)
    {
        int a = 10, b = 3;
        System.out.println("Addition: " + (a + b));
        System.out.println("Subtraction: " + (a - b));
        System.out.println("Multiplication: " + (a * b));
        System.out.println("Division: " + (a / b));
        System.out.println("Modulus: " + (a % b));
    }
}

Output:

Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3
Modulus: 1
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 31. (a) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×