Lecture An introduction to computer science using java (2nd Edition): Chapter 3 - S.N. Kamin, D. Mickunas, E. Reingold

Chapter 3 - Fundamental data types of Java. In this chapter we will: Discuss four important data types: integers, real numbers, strings, characters; describe the process of developing and debugging a Java program. | Chapter 3 Fundamental Data Types of Java Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: discuss four important data types integers real numbers strings characters describe the process of developing and debugging a Java program Integers Numbers without fractional parts 3, 47, -12 Variables can be used to store integers using an assignment statement int daysInWeek; daysInWeek = 7; In general integer variables may be used any place an integer literal can be Reading Integers import CSLib.*; Inputbox in; int i; in = newInputBox(); (“Enter an integer: “); i = (); Integer Arithmetic Operations Symbol Operation Example + Addition 45 + 5 = 50 - Subtraction 657 – 57 = 600 * Multiplication 7000 * 3 = 2100 / Division 10 / 3 = 3 % Remainder 10 % 3 = 1 Precedence Rules Evaluate all subexpressions in parentheses Evaluate nested parentheses from the inside out In the absence of parentheses or within parentheses Evaluate *, /, or % before + or – Evaluate sequences of *, /, and % operators from left to right Evaluate sequences of + and – operators from left to right Precedence Examples Example 1 6 + 37 % 8 / 5 is the same as 6 + ((37 % 8) / 5) = 6 + ( 5 / 5) = 7 Example 2 6 + 37 % (8 / 5) = 6 + 37 % 1 = 6 + 0 = 6 Additional Integer Operators Self-assignment temperature = temperature + 10; Increment cent++; equivalent to cent = cent + 1; Decrement cent--; equivalent to cent = cent - 1; Initializers May be used to give variables initial values int x = 5; int y = 6; Can be written more concisely int x = 5, y = 6; Can use expressions on the right hand side int x = 5, y = x + 1; Symbolic Constants Useful when you want a variable whose value never changes Use the modifier final in its declaration Example final int US_Population = 278058881; Real Numbers Numbers with fractional parts , , , , Declared using the type | Chapter 3 Fundamental Data Types of Java Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: discuss four important data types integers real numbers strings characters describe the process of developing and debugging a Java program Integers Numbers without fractional parts 3, 47, -12 Variables can be used to store integers using an assignment statement int daysInWeek; daysInWeek = 7; In general integer variables may be used any place an integer literal can be Reading Integers import CSLib.*; Inputbox in; int i; in = newInputBox(); (“Enter an integer: “); i = (); Integer Arithmetic Operations Symbol Operation Example + Addition 45 + 5 = 50 - Subtraction 657 – 57 = 600 * Multiplication 7000 * 3 = 2100 / Division 10 / 3 = 3 % Remainder 10 % 3 = 1 Precedence Rules Evaluate all subexpressions in parentheses Evaluate nested parentheses from the inside .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.