AP® Computer Science A glossary

Casting

Also called: type casting

Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods

Converting a value between double and int with the casting operators (int) and (double).

Appears in the course and exam description (CED): 1.5.A.1

(int) turns a double into an int by truncating; (double) turns an int into a double. A cast applies only to the value right after it.

System.out.println((int) 3.86);
System.out.println((double) 7 / 2);
System.out.println((double) (7 / 2));

Output:

3
3.5
3.0
Learn it properly, with a checkpoint 1.5 Casting and Range of Variables

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure