0 day streak
java / beginner
Snippet

Basic Arithmetic Operators

Java supports standard mathematical operators to perform calculations on numeric variables.

snippet.java
java
1
2
3
4
5
int a = 10;
int b = 5;
int sum = a + b;
int product = a * b;
int quotient = a / b;
Breakdown
1
int sum = a + b;
Uses the + operator to add two numbers.
2
int product = a * b;
Uses the * operator to multiply two numbers.
3
int quotient = a / b;
Uses the / operator for integer division.