电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

java语言程序设计课后习题答案

java语言程序设计课后习题答案_第1页
1/7
java语言程序设计课后习题答案_第2页
2/7
java语言程序设计课后习题答案_第3页
3/7
习题2 3.使用“= =”对相同内容的字符串进行比较,看会产生什么样的结果。 答:首先创建一个字符串变量有两种方式: String str = new String("abc"); String str = "abc"; 使用“= =”会因为创建的形式不同而产生不同的结果: 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 因此自符串如果是对内容进行比较,使用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.equals(str2)); //true String str1 = new String("abc"); String str2 = new String("abc"); System.out.println(str1.equals(str2)); //true 5.编写一个程序,把变量 n的初始值设置为 1678,然后利用除法运算和取余运算把变量的每位数字都提出来并打印,输出结果为:n=1678。n的每位数字是 1,6,7,8。若 n为任意值呢? 法一: 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为任意值 import java.io.*; 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;...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

java语言程序设计课后习题答案

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部