Chapter 5
Working with Numbers and Expressions
IN THIS CHAPTER
Dealing with operators, such as +, –, *, and /
Creating finely crafted expressions
Using the Math class
Formatting your numbers
In Chapter 4, you discover the various primitive numeric types that are supported by Java. In this chapter, you build on that knowledge by doing basic operations with numbers. Much of this chapter focuses on the complex topic of expressions, which combine numbers with operators to perform calculations. This chapter also covers performing advanced calculations using the Math class and techniques for formatting numbers when you display them.
Working with Arithmetic Operators
An operator is a special symbol or keyword that’s used to designate a mathematical operation or some other type of operation that can be performed on one or more values, called operands. In all, Java has about 40 operators. This chapter focuses on the operators that do arithmetic. These arithmetic operators — seven of them in all, summarized in Table 5-1 — perform basic arithmetic operations, such as addition, subtraction, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access