java语言程序设计课后习题答案.doc
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
![preview](https://dl-preview.csdnimg.cn/28973356/0001-c3b6d43cd0e47aa6f7ab274175d9d58d_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
Java 语言程序设计课后习题答案 本资源提供了 Java 语言程序设计课后习题答案,涵盖了字符串比较、变量操作等知识点。 知识点一:字符串比较 * 在 Java 中,使用“==”对字符串进行比较会产生不同的结果,原因是字符串的创建形式不同。 * 使用“==”会比较字符串的引用,而不是字符串的内容。 * 使用equals方法比较字符串的内容,才是可靠的方式。 例如: String str1 = "abc"; String str2 = "abc"; System.out.println(str1==str2);//true String str1 = new String("abc"); String str2 = "abc"; System.out.println(str1==str2);//false String str1 = new String("abc"); String str2 = new String("abc"); System.out.println(str1==str2);//false String str1 = "abc"; String str2 = "abc"; System.out.println(str1.equals(str2));//true String str1 = new String("abc"); String str2 = "abc"; System.out.println(str1.equals(str2));//true String str1 = new String("abc"); String str2 = new String("abc"); System.out.println(str1.equals(str2));//true 知识点二:变量操作 * 变量可以通过除法运算和取余运算来提取每位数字。 * 可以使用整数除法和取余运算来提取变量的每位数字。 * 也可以使用字符串来实现变量的每位数字提取。 例如: public class Exercise5{ public static void main(String[]args){ int n=1678; int unit; int decimal; int hundred; int thousand; int count; thousand=n/1000; count=n%1000; hundred=count/100; count=count%100; decimal=count/10; count=count%10; unit=count; System.out.println("1678 包含的数字分别是:"+thousand+','+hundred+','+decimal+','+unit); } } 如果 n 为任意值,可以使用以下方法: public class Exercise51{ public static void main(String[]args) throws IOException{ System.out.print("请输 入 一 个 整数:"); InputStreamReader isStream=new InputStreamReader(System.in); BufferedReader bfReader=new BufferedReader(isStream); String input=bfReader.readLine(); int length=input.length()-1; int n=new Integer(input).intValue(); while(length>=0){ int divisor=(int) Math.pow(10,length); length=length-1; int output=n/divisor; n=n%divisor; System.out.print(output+","); } } } 本资源提供了字符串比较和变量操作的知识点,并提供了实践代码供读者学习和实践。
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
- 粉丝: 21
- 资源: 18万+
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)