Concept Flow - Arithmetic operators
Start
Initialize variables
Apply +, -, *, /, %
Store results
Print results
End
This flow shows how arithmetic operators take values, perform calculations, and store or display the results.
int a = 10; int b = 3; int sum = a + b; int diff = a - b; int prod = a * b; int quot = a / b; int mod = a % b; System.out.println(sum + ", " + diff + ", " + prod + ", " + quot + ", " + mod);
| Step | Operation | Expression | Result | Explanation |
|---|---|---|---|---|
| 1 | Addition | sum = a + b | 13 | 10 + 3 = 13 |
| 2 | Subtraction | diff = a - b | 7 | 10 - 3 = 7 |
| 3 | Multiplication | prod = a * b | 30 | 10 * 3 = 30 |
| 4 | Division | quot = a / b | 3 | Integer division 10 / 3 = 3 |
| 5 | Modulo | mod = a % b | 1 | Remainder of 10 / 3 is 1 |
| 6 | System.out.println(...) | 13, 7, 30, 3, 1 | Outputs all results | |
| 7 | End | - | - | Program ends |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | After Step 5 | Final |
|---|---|---|---|---|---|---|---|
| a | 10 | 10 | 10 | 10 | 10 | 10 | 10 |
| b | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
| sum | undefined | 13 | 13 | 13 | 13 | 13 | 13 |
| diff | undefined | undefined | 7 | 7 | 7 | 7 | 7 |
| prod | undefined | undefined | undefined | 30 | 30 | 30 | 30 |
| quot | undefined | undefined | undefined | undefined | 3 | 3 | 3 |
| mod | undefined | undefined | undefined | undefined | undefined | 1 | 1 |
Arithmetic operators in Java: + (add), - (subtract), * (multiply), / (divide), % (modulo) Operate on numbers and produce results. Integer division discards decimals. Modulo gives remainder. Store results in variables.
%.a and b?*.int result = a * b; correctly multiplies a and b.int x = 10; int y = 3; System.out.println(x / y);
x and y are integers, so division drops the decimal part.int a = 5; int b = 0; int c = a / b; System.out.println(c);
a by b, where b is zero.result after execution?int a = 15; int b = 4; int result = a / b + a % b * 2;
Pass the test and this pattern moves unknown