Back to Primitive Types

Lesson PreviewLesson 3 of 7 in this unit

1.3 Expressions and Assignment Statements

Part of Primitive Types in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

We use operators to implement math and logic in our code. Take a look at this example:

java
System.out.println(12 + 6); 
// we use the + operator to add

System.out.println(12 - 6); 
// we use the - operator to subtract

System.out.println(12 * 6); 
// we use the * operator to multiply

System.out.println(12 / 6); 
// we use the / operator to divide

System.out.println(12 % 6); 
// we use the % operator, called the modulus operator, to get the remainder if we were to divide the two numbers

Output

18
6
72
2
0

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.