Lecture Java: Chapter 2
Số trang: 98
Loại file: pptx
Dung lượng: 1.56 MB
Lượt xem: 16
Lượt tải: 0
Xem trước 10 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Lecture Java: Chapter 2 (Data and Expressions) presented Character Strings, Variables and Assignment, Primitive Data Types, Expressions, Data Conversion, Interactive Programs, Graphics, Applets, Drawing Shapes.
Nội dung trích xuất từ tài liệu:
Lecture Java: Chapter 2 Chapter 2Data and Expressions Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Copyright © 2012 Pearson Education, Inc. Data and Expressions• Lets explore some other fundamental programming concepts• Chapter 2 focuses on: – character strings – primitive data – the declaration and use of variables – expressions and operator precedence – data conversions – accepting input from the user – Java applets – introduction to graphics Copyright © 2012 Pearson Education, Inc.Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes Copyright © 2012 Pearson Education, Inc.Character Strings• A string literal is represented by putting double quotes around the text• Examples:This is a string literal.123 Main StreetX• Every character string is an object in Java, defined by the String class• Every string literal represents a String object Copyright © 2012 Pearson Education, Inc.The println Method• In the Lincoln program from Chapter 1, we invoked the println method to print a character string• The System.out object represents a destination (the monitor screen) to which we can send output System.out.println (Whatever you are, be a good one.); method object name information provided to the method (parameters) Copyright © 2012 Pearson Education, Inc.The print Method• The System.out object provides another service as well• The print method is similar to the println method, except that it does not advance to the next line• Therefore anything printed after a print statement will appear on the same line• See Countdown.java Copyright © 2012 Pearson Education, Inc.//********************************************************************// Countdown.java Author: Lewis/Loftus//// Demonstrates the difference between print and println.//********************************************************************public class Countdown{ //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print (Three... ); System.out.print (Two... ); System.out.print (One... ); System.out.print (Zero... ); System.out.println (Liftoff!); // appears on first output line System.out.println (Houston, we have a problem.); }} Copyright © 2012 Pearson Education, Inc. Output//********************************************************************// Countdown.java Author: Lewis/Loftus// Three... Two... One... Zero... Liftoff!// Demonstrates the we have between print and println. Houston, difference a problem.//********************************************************************public class Countdown{ //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print (Three... ); System.out.print (Two... ); System.out.print (One... ); System.out.print (Zero... ); System.out.println (Liftoff!); // appears on first output line System.out.println (Houston, we have a problem.); }} Copyright © 2012 Pearson Education, Inc.String Concatenation• The string concatenation operator (+) is used to append one string to the end of another Peanut butter + and jelly• It can also be used to append a number to a string• A string literal cannot be broken across two lines in a program• See Facts.java Copyright © 2012 Pearson Education, Inc.//********************************************************************// Facts.java Author: Lewis/Loftus//// Demonstrates the use of the string concatenation operator and the// automatic conversion of an integer to a string.//********************************************************************public class Facts{ //---------------------- ...
Nội dung trích xuất từ tài liệu:
Lecture Java: Chapter 2 Chapter 2Data and Expressions Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Copyright © 2012 Pearson Education, Inc. Data and Expressions• Lets explore some other fundamental programming concepts• Chapter 2 focuses on: – character strings – primitive data – the declaration and use of variables – expressions and operator precedence – data conversions – accepting input from the user – Java applets – introduction to graphics Copyright © 2012 Pearson Education, Inc.Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes Copyright © 2012 Pearson Education, Inc.Character Strings• A string literal is represented by putting double quotes around the text• Examples:This is a string literal.123 Main StreetX• Every character string is an object in Java, defined by the String class• Every string literal represents a String object Copyright © 2012 Pearson Education, Inc.The println Method• In the Lincoln program from Chapter 1, we invoked the println method to print a character string• The System.out object represents a destination (the monitor screen) to which we can send output System.out.println (Whatever you are, be a good one.); method object name information provided to the method (parameters) Copyright © 2012 Pearson Education, Inc.The print Method• The System.out object provides another service as well• The print method is similar to the println method, except that it does not advance to the next line• Therefore anything printed after a print statement will appear on the same line• See Countdown.java Copyright © 2012 Pearson Education, Inc.//********************************************************************// Countdown.java Author: Lewis/Loftus//// Demonstrates the difference between print and println.//********************************************************************public class Countdown{ //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print (Three... ); System.out.print (Two... ); System.out.print (One... ); System.out.print (Zero... ); System.out.println (Liftoff!); // appears on first output line System.out.println (Houston, we have a problem.); }} Copyright © 2012 Pearson Education, Inc. Output//********************************************************************// Countdown.java Author: Lewis/Loftus// Three... Two... One... Zero... Liftoff!// Demonstrates the we have between print and println. Houston, difference a problem.//********************************************************************public class Countdown{ //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print (Three... ); System.out.print (Two... ); System.out.print (One... ); System.out.print (Zero... ); System.out.println (Liftoff!); // appears on first output line System.out.println (Houston, we have a problem.); }} Copyright © 2012 Pearson Education, Inc.String Concatenation• The string concatenation operator (+) is used to append one string to the end of another Peanut butter + and jelly• It can also be used to append a number to a string• A string literal cannot be broken across two lines in a program• See Facts.java Copyright © 2012 Pearson Education, Inc.//********************************************************************// Facts.java Author: Lewis/Loftus//// Demonstrates the use of the string concatenation operator and the// automatic conversion of an integer to a string.//********************************************************************public class Facts{ //---------------------- ...
Tìm kiếm theo từ khóa liên quan:
Kỹ thuật lập trình Lecture Java Chapter 1 Lập trình Java Lập trình Mobile Ngôn ngữ lập trình Công nghệ thông tinGợi ý tài liệu liên quan:
-
52 trang 429 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 312 0 0 -
74 trang 295 0 0
-
96 trang 291 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 279 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 274 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 272 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 264 0 0