Đang chuẩn bị liên kết để tải về tài liệu:
Lecture An Introduction to Object-Oriented Programming with Java (4/e): Chapter 3 - C. Thomas Wu

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Chapter 3 - Numerical data. After you have read and studied this chapter, you should be able to: Select proper types for numerical data; write arithmetic expressions in Java; evaluate arithmetic expressions using the precedence rules; describe how the memory allocation works for objects and primitive data values; write mathematical expressions, using methods in the Math class; generate pseudo random numbers. | Chapter 3 Numerical Data 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write arithmetic expressions in Java. Evaluate arithmetic expressions using the precedence rules. Describe how the memory allocation works for objects and primitive data values. Write mathematical expressions, using methods in the Math class. Use the GregorianCalendar class in manipulating date information such as year, month, and day. Use the DecimalFormat class to format numerical data Convert input string values to numerical data Perform input and output by using System.in and System.out 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Manipulating Numbers In Java, to add two numbers x and y, we write x + y But before the actual addition of the two numbers takes place, we must declare their data type. If x and y are integers, we write int x, y; or int x; int y; 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Variables When the declaration is made, memory space is allocated to store the values of x and y. x and y are called variables. A variable has three properties: A memory location to store the value, The type of data stored in the memory location, and The name used to refer to the memory location. Sample variable declarations: int x; int v, w, y; 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Numerical Data Types There are six numerical data types: byte, short, int, long, float, and double. Sample variable declarations: int i, j, k; float numberOne, numberTwo; long bigInteger; double bigNumber; At the time a variable is declared, it also can be initialized. For example, we may initialize the integer variables count and height to 10 and 34 as . | Chapter 3 Numerical Data 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Objectives After you have read and studied this chapter, you should be able to Select proper types for numerical data. Write arithmetic expressions in Java. Evaluate arithmetic expressions using the precedence rules. Describe how the memory allocation works for objects and primitive data values. Write mathematical expressions, using methods in the Math class. Use the GregorianCalendar class in manipulating date information such as year, month, and day. Use the DecimalFormat class to format numerical data Convert input string values to numerical data Perform input and output by using System.in and System.out 4th Ed Chapter 3 - ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Manipulating Numbers In Java, to add two numbers x and y, we write x + y But before the actual addition of the two numbers takes place, we must .