正在加载图片...
Appendix E Java Primer E.1.4.2 The while statement The format of the while loop is as follows: while(boolean condition is true){ /body of loop The format of the do-while loop is as follows: do /body of loop while (boolean condition is true); As is the case for the for loop,if the body of either the while or the do-while loops is only one statement,the braces can be eliminated. E.1.4.3 The if statement The format of the if statement is as follows: if (boolean condition is true){ /statement(s) else if (boolean condition is true){ /other statement(s) else /even other statement(s) If there is only a single statement to be performed if the Boolean expression is true,then the braces can be eliminated. E.1.5 Data Types Java provides two different varieties of data types:primitive and reference(or nonprimitive).Primitive data types include boolean,char,byte,short, int,long,float,and double.Reference data types include objects and arrays. E.1.6 Classes and Objects Objects are at the heart of Java programming.An object consists of data and methods that access(and possibly manipulate)the data.An object also has a state,which consists of the values for the object's data at a particular time. Objects are modeled with classes.Figure E.3 is a class for a Point.The data for this class are the x and y coordinates for the point.An object-which is an instance of this class-can be created with the new statement.For example,the statement Point ptA new Point(0,15);4 Appendix E Java Primer E.1.4.2 The while statement The format of the while loop is as follows: while (boolean condition is true) { // body of loop } The format of the do-while loop is as follows: do { // body of loop } while (boolean condition is true); As is the case for the for loop, if the body of either the while or the do-while loops is only one statement, the braces can be eliminated. E.1.4.3 The if statement The format of the if statement is as follows: if (boolean condition is true) { // statement(s) } else if (boolean condition is true) { // other statement(s) } else { // even other statement(s) } If there is only a single statement to be performed if the Boolean expression is true, then the braces can be eliminated. E.1.5 Data Types Java provides two different varieties of data types: primitive and reference (or nonprimitive). Primitive data types include boolean, char, byte, short, int, long, float, and double. Reference data types include objects and arrays. E.1.6 Classes and Objects Objects are at the heart of Java programming. An object consists of data and methods that access (and possibly manipulate) the data. An object also has a state, which consists of the values for the object’s data at a particular time. Objects are modeled with classes. Figure E.3 is a class for a Point. The data for this class are the x and y coordinates for the point. An object—which is an instance of this class—can be created with the new statement. For example, the statement Point ptA = new Point(0,15);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有