JAVA编程思想(第四版)课后答案_第1页
JAVA编程思想(第四版)课后答案_第2页
JAVA编程思想(第四版)课后答案_第3页
JAVA编程思想(第四版)课后答案_第4页
JAVA编程思想(第四版)课后答案_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、java编程思想(第四版)课后答案java编程思想(第四版)课后答案 编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(java编程思想(第四版)课后答案)的内容能够给您的工作和学习带来便利。同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快 业绩进步,以下为java编程思想(第四版)课后答案的全部内容。java编程思想(第四版)习题答案第二章练习1:public class pr

2、imitivetest static int i;static char c;public static void main(string args) system。out.println(int = ” + i);system。out.println(char = + c);练习2:public class helloworld public static void main(string args) system。out.println(”hello world!);练习3:public class atntest public static void main(string args)

3、class atypename int i;double d;boolean b;void show() system。out。println(i);system.out.println(d);system.out。println(b);atypename a = new atypename();a。i = 3;a。d = 2.71828;a.b = false;a。show();练习4:public class dataonlytest public static void main(string args) class dataonly int i;double d;boolean b;v

4、oid show() system。out.println(i);system.out。println(d);system.out。println(b);dataonly data = new dataonly();data。i = 3;data.d = 2。71828;data.b = false;data。show();练习5:public class dotest2 public static void main(string args) class dataonly int i;double d;boolean b;void show() system。out。println(i);s

5、ystem.out.println(d);system.out。println(b);dataonly data = new dataonly();data.i = 234;data。d = 2。1234545;data.b = true;data.show();练习6:public class storagetest public static void main(string args) class storestuff int storage(string s) return s.length() * 2;storestuff x = new storestuff();system.ou

6、t。println(x.storage(”hi);练习7:class statictest static int i = 47;class incrementable static void increment() statictest.i+; public class itest public static void main(string args) system.out。println(statictest.i= ” + statictest。i);statictest st1 = new statictest();statictest st2 = new statictest();sy

7、stem.out。println(st1.i= ” + st1.i);system。out。println(st2.i= + st2。i);incrementable sf = new incrementable();sf.increment();system.out.println(”after sf。increment() called: );system。out。println(”st1。i = + st1。i);system.out.println(”st2.i = + st2。i);incrementable.increment();system。out。println(”after

8、 incrementable.increment called: );system.out。println(”st1.i = + st1。i);system.out。println(”st2.i = + st2.i);练习8:class statictest static int i = 47;class incrementable static void increment() statictest.i+; public class onestatictest public static void main(string args) system。out.println(”statictes

9、t.i= + statictest.i);statictest st1 = new statictest();statictest st2 = new statictest();system。out.println(st1.i= + st1。i);system.out.println(st2。i= + st2.i);incrementable.increment();system。out.println(after incrementable。increment() called: ”);system。out。println(st1。i = + st1。i);system。out。printl

10、n(st2。i = ” + st2。i);incrementable。increment();system.out.println(”after incrementable。increment called: ”);system.out。println(st1.i = + st1。i);system。out.println(”st2.i = ” + st2。i);st1.i = 3;system.out.println(”after st1.i = 3, );system.out.println(”st1.i = + st1.i);system。out。println(st2.i = ” +

11、st2.i);system。out。println(create another statictest, st3.”);statictest st3 = new statictest();system.out。println(”st3。i = ” + st3。i);练习9:public class autoboxtest public static void main(string args) boolean b = false;char c = x;byte t = 8;short s = 16;int i = 32;long l = 64;float f = 0。32f;double d

12、= 0。64;boolean b = b;system。out。println(boolean b = ” + b); system.out.println(boolean b = + b); character c = c;system.out.println(”char c = + c);system.out。println(character c = + c);byte t = t;system.out。println(byte t = + t);system。out.println(byte t = ” + t);short s = s;system。out.println(”shor

13、t s = ” + s);system。out.println(”short s = + s);integer i = i;system。out。println(int i = + i);system。out。println(”integer i = + i);long l = l;system。out。println(long l = + l);system。out。println(long l = + l);float f = f;system。out.println(float f = + f);system。out。println(float f = ” + f);double d =

14、 d;system。out.println(”double d = ” + d);system.out.println(”double d = + d);练习10:public class commandargtest public static void main(string args) intargs1=1,2,3;system。out。println(args0 = + args10);system.out.println(args1 = + args11);system。out。println(”args2 = + args12);练习11:public class rainbow

15、public static void main(string args) allthecolorsoftherainbow atc = new allthecolorsoftherainbow();system.out.println(”atc。anintegerrepresentingcolors = + atc.anintegerrepresentingcolors);atc。changecolor(7);atc.changethehueofthecolor(77);system。out。println(”after color change, atc.anintegerrepresent

16、ingcolors = + atc.anintegerrepresentingcolors);system.out。println(atc.hue = ” + atc。hue);class allthecolorsoftherainbow int anintegerrepresentingcolors = 0;int hue = 0;void changethehueofthecolor(int newhue) hue = newhue;int changecolor(int newcolor) return anintegerrepresentingcolors = newcolor;练习1

17、2:public class doctest / entry poing to class application.* param args array of string arguments* throws exceptions no exceptions thrown*/public static void main(string args) system。out。println(hello, its: ”);system。out.println(new date();练习131:public class documentation1 /* a field comment */public

18、 int i;/* a method comment /public void f() 2:public class documentation2 date d = new date();void showdate() system。out.println(”date = ” + d);3:public class documentation3 public static void main(string args) date d = new date();system。out.println(d = ” + d);练习14:public class documentation4 public

19、 int i = 2;private int j = 3;public static void main(string args) date d = new date();system。out。println(d = ” + d);练习15:public class hellodoctest public static void main(string args) system.out.println(hello world!);练习16:class tree int height;tree() system.out.println(planting a seedling);height =

20、0;tree(int initialheight) height = initialheight;system。out。println(creating new tree that is + height + feet tall”);void info() system.out。println(tree is ” + height + feet tall);void info(string s) system。out.println(s + ”: tree is + height + feet tall”);public class overloading public static void

21、 main(string args) for(int i = 0; i 5; i+) tree t = new tree(i);();(”overloading method);/ overloaded constructor:new tree();第三章练习1:public class printtest public static void main(string args) print(”hello, from short form.);p。rintln(hello from greggordon form.);system.out。println(hello f

22、rom long form.);练习2:class tube float level;public class assign public static void main(string args) tube t1 = new tube();tube t2 = new tube();t1。level = 0.9f;t2。level = 0.47f;p。rintln(”1: t1.level: ” + t1.level + , t2。level: ” + t2.level);t1 = t2;p.rintln(”2: t1.level: ” + t1.level + ”, t2。level: ”

23、+ t2.level);t1。level = 0。27f; p。rintln(”3: t1。level: ” + t1.level + , t2。level: ” + t2.level);练习3:class box float a;public class passobject2 static void f(box y) y.a = 2.71828f;public static void main(string args) box x = new box();x.a = 3。1416f;print(1: x.a = + x。a);f(x);print(2: x.a = ” + x。a);练习4

24、:class velocitycalculator static float velocity (float d, float t) if(t = 0) return 0f;else return d/t; public class velocitytester public static void main(string args) float d = 565.3f;float t = 3.6f;system.out.println(distance: ” + d);system.out.println(time: ” + t);float v = velocitycalculator。ve

25、locity(d, t);system。out.println(”velocity: ” + v);练习5:class dog string name;string says;void setname(string n) name = n;void setsays(string s) says = s;void showname() p。rintln(name);void speak() p。rintln(says);public class dogtest public static void main(string args) dog spot = new dog();spot。setna

26、me(”spot”);spot.setsays(ruff!);dog scruffy = new dog();scruffy。setname(”scruffy”);scruffy.setsays(”wurf!);spot。showname();spot。speak();scruffy。showname(); scruffy。speak();练习6:class dog string name;string says;void setname(string n) name = n;void setsays(string s) says = s;void showname() p.rintln(name);void speak() p.ri

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论