- 13
- 0
- 约1.32万字
- 约 75页
- 2017-03-30 发布于四川
- 举报
第2章节-java基本语法
2.4.4 字符串 Java使用java.lang包中的String类来创建字符串变量,所以字符串变量实质上是一个对象。 使用方式: String s=good students; String s=new String(good students); Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 字符串练习: String s=I am a good student; String s[ ]=I am a good student; String s[ ]={ I am a good student }; 这三种表达方式都正确吗?怎样对正确的内容进行打印? Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 2.5 运算符和表达式 2.5.1 算术运算符和算术表达式 1. 加减运算符:+ - 2. 乘除和求余运算符:* / % 自增、自减运算符 运算符放在操作元前++a;--a;使用a之前,先使a加(减)1; 运算符放在操作元后a++; a--;使用a之后,再使a加(减)1; Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 自增、自减运算符 例1:a=3; y=++a;例2: a=3; z=a++;则: 例1: a=4;y=4; 例2: a=4; z=3; Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 练习 public class Test { public static void main(String args[]){ int x=4,y=2; float z=x%y; int m=x/y; int n=++x; int k=x++; System.out.println(“z=“+z); System.out.println(“m=“+m); System.out.println(“n=“+n); System.out.println(“k=“+k); System.out.println(“x=“+x); } } Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 练习题答案 Z=0.0 m=2 n=5 k=5 x=6 Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 算术混合运算的精度 精度由“低”到“高”的顺序是: byte, short, int, long, float, double Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 算术混合运算的精度 Java按运算符两边操作元的最高精度保留结果的精度。例:int x=5; int y=5/2; System.out.println(y); 思考: y=? 如何才能得到2.5? Char型和整型数据进行算术混合运算后结果是int型。例:int x=7;int y=x+C;思考:如何才能得到char类型的结果? Evaluation only. Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0. Copyright 2004-2011 Aspose Pty Ltd. 2.5.2 关系运算符
原创力文档

文档评论(0)