Integer Arithmetic and Output

Part of: Primitive Types

Arithmetic Operators Java provides five core arithmetic operators for numbers: - + addition - - subtraction - multiplication - / division - % modulus (remainder) When both operands are int, the result is an int. This lesson focuses on integer math with +, -, and ; division is covered next. Printing Output Java has two main ways to send text to the console: - System.out.println(x) prints x then moves to a new line . - System.out.print(x) prints x and stays on the same line . Notice how print lets you build a line piece by piece, while println finishes the line. String Concatenation The + operator does double duty. With numbers it adds; with a String on either side it concatenates (joins text): Here total is converted to text and glued after "Total = ". Be careful: "x" + 2 + 3 produces x23 (left to right), but 2 + 3 + "x" produces 5x because the numeric addition happens first. Putting It Together Most programs read input, compute with arithmetic, and print a result. Mastering integer operators plus print/println lets you produce exactly the output a problem requires, spacing and newlines included. The exam frequently tests whether you can predict console output precisely, so trace ea

Challenge: Labeled Sum