《JAVA OOP开发》英文版 Chapter 3 Numerical Data

Chapter 3 Numerical data 2000 McGraw-Hl‖ Introduction to Object-Oriented Programming with Java-Wu Chapter 3-1
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 1 Chapter 3 Numerical Data

Chapter 3 objectives After you have read and studied this chapter, you should be able to e Select proper types for numerical data e Write arithmetic expressions in Java Evaluate arithmetic expressions using the precedence rules e Describe how the memory allocation works for objects and primitive data values e Write mathematical expressions using methods in the Math class e Write programs that input and output data using the Input Box and OutputBox classes from the javabook package Apply the incremental development technique in writing programs (Optional) Describe how the integers and real numbers are represented in memory. C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-2
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 2 Chapter 3 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. Write programs that input and output data using the InputBox and OutputBox classes from the javabook package. Apply the incremental development technique in writing programs. (Optional) Describe how the integers and real numbers are represented in memory

Manipulating Numbers r In Java, to add two numbers x and y, we write Y r 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, yi or int xi int yi C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-3
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 3 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;

Variables r When the declaration is made, memory space is llocated to store the values of x and y x and y are called variables. a variable has three properties: aA memory location to store the value a The type of data stored in the memory location, and a The name used to refer to the memory location. r Sample variable declarations: int xi int v, W, y C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-4
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 4 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;

Numerical data Types r There are six numerical data types: byte, short, int, long float, and double r Sample variable declarations int i,j, ki float number one, numberTwoi long big integer double bigNumber r 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 int count =10, height =34 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-5
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 5 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 int count = 10, height = 34;

Data Type Precisions The six data types differ in the precision of values they can store in memory Data Default Minimum Maximum Type ContentValuet Value Value byte Integer 127 short Integer 0000 -32768 32767 ant Integer 2147483648 2147483647 Integer 9223372036854775808 9223372036854775807 float Real 0.0 340282347E+38tt 3.40282347E+38 doubl Real 0.0 179769313486231570E+308179769313486231570E+308 f. No default value is assigned to a local variable. A local variable is explained on page 162 tt. The character E indicates a number is expressed in scientific notation. This notation is explained on page 99 C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-6
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 6 Data Type Precisions The six data types differ in the precision of values they can store in memory

Assignment statements r We assign a value to a variable using an assignment statements. r The syntax is = i r Examples: sum firstNumber secondnumber avg =(one two three)/3.0 C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-7
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 7 Assignment Statements We assign a value to a variable using an assignment statements. The syntax is = ; Examples: sum = firstNumber + secondNumber; avg = (one + two + three) / 3.0;

Primitive data Declaration and assignments int firstNumber, secondNumberi firstNumber 234 secondNumber =87: A. Variables are allocated in memory A firstNumber 234 int firstNumber, secondNumberi secondNumber 87 firstNumber 234 secondNumber =87; B B. Values are assigned Code State of memo C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-8
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 8 Primitive Data Declaration and Assignments Code State of Memory int firstNumber, secondNumber; firstNumber = 234; secondNumber = 87; A B int firstNumber, secondNumber; firstNumber = 234; secondNumber = 87; firstNumber secondNumber A. Variables are allocated in memory. B. Values are assigned to variables. 234 87

Assigning Numerical Data int number; number 237 number =35/ number 35 A. The variable is allocated in int numberi A memory. number =237 B B. The value 237 number =35: is assigned to number C. The value 35 overwrites the previous value 237. Code State of Memory C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 3-9
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 9 Assigning Numerical Data Code State of Memory int number; number = 237; number = 35; number A. The variable is allocated in memory. B. The value 237 is assigned to number. 237 int number; number = 237; number = 35; A B number = 35; C C. The value 35 overwrites the previous value 237. 35

Assigning Objects Customer customer customer customer new Customer()i customer new Customer( )i C Cus A B Customer customer A. The variable is allocated in memory customer new Customer()i B. The reference to the cus tomer new Customer()i new object is assigned to customer. C) C. The refer another object overwrites the reference in customer. Code State of memo C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3-10
© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 3 - 10 Assigning Objects Code State of Memory Customer customer; customer = new Customer( ); customer = new Customer( ); customer A. The variable is allocated in memory. Customer customer; customer = new Customer( ); customer = new Customer( ); A B C customer = new Customer( ); B. The reference to the new object is assigned to customer. Customer C. The reference to another object overwrites the reference in customer. Customer
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《JAVA OOP开发》英文版 Chapter 2 Java Programming Basics.ppt
- 《JAVA OOP开发》英文版 Chapter 1 Introduction to Object-oriented Programming and Software Development.ppt
- 《JAVA OOP开发》英文版 Introduction to Computers and Programming Languages.ppt
- 《Windows DNA应用程式》 面向对象分析与设计讲义.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第四章 第四讲 分支结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十二章 文件.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第十一章 复杂数据类型及排序.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第六讲 数组.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第六讲 数组.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章(7-2)指针与指针变量.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第五章 循环结构.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第二章 数据类型与运算符.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第二讲 数据类型与算术运算.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第九讲 函数.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第九章 函数.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第三章 运算符与表达式.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第三讲 运算与顺序结构.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第七章 指针.ppt
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(教案讲义)第七讲 数据存储机制.doc
- 北大青鸟:《程序设计基础:C语言实现》课程教学资源(PPT课件讲稿)第一章 C语言基础.ppt
- 《JAVA OOP开发》英文版 Chapter 4 Defining Instantiable Classes.ppt
- 《JAVA OOP开发》英文版 Chapter 5 Processing Input with Applets.ppt
- 《JAVA OOP开发》英文版 Chapter 6 Selection statements.ppt
- 《JAVA OOP开发》英文版 Chapter 7 Repetition Statements.ppt
- 《JAVA OOP开发》英文版 Chapter 8 Characters and strings.ppt
- 《JAVA OOP开发》英文版 Chapter 9 objectives.ppt
- 《JAVA OOP开发》英文版 Chapter 10 Sorting and Searching.ppt
- 《JAVA OOP开发》英文版 Chapter 11 File Input and Output.ppt
- 《JAVA OOP开发》英文版 Chapter 12 Reusable classes and packages.ppt
- 《JAVA OOP开发》英文版 Chapter 13 GUI Objects and Event-Driven Programming.ppt
- 《JAVA OOP开发》英文版 Chapter 14 Inheritance and Polymorphism.ppt
- 《JAVA OOP开发》英文版 Chapter 15 Case Study Class Roster Maintenance program.ppt
- 《JAVA OOP开发》英文版 Chapter 16 Chapter 16 Recursive algorithms.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第一章 绪论.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第七章 牛行接与应用.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第三章 MCS-51单片机指令系统.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第九章 A/D、D/A转换接口.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第二章 MCS-51学机组成理.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第五章 输入/输出与中断.ppt
- 人民邮电出版社:高职高专现代信息技术系列教材《单片机原理与接口技术》课程电子教案(PPT课件讲稿)第八章 并行接口与应用.ppt