JAVA编程思想课后习题答案-.pdf
《JAVA编程思想课后习题答案-.pdf》由会员分享,可在线阅读,更多相关《JAVA编程思想课后习题答案-.pdf(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Java编程思想(第四版)习题答案第二章练习 1:public class PrimitiveTest 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
2、 static void main(String args)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
3、;double d;boolean b;void 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.p
4、rintln(i);System.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.out.
5、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();System.out.printl
6、n(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 Incrementable.increment called:);S
7、ystem.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(StaticTest.i=+StaticTest.i);StaticTest st1=new StaticTest(
8、);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.println(st2.i=+st2.i);Incrementable.increment();System.out.println(Afte
9、r 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=+st2.i);System.out.println(Create another StaticTest,st3.);StaticTest st3=new StaticTest();System.
10、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=0.64;Boolean B=b;System.out.println(boolean b=+b);System.out.println(Boolean B=+B);Character C=c;System.out.println(char
11、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(short 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);Syste
12、m.out.println(Long L=+L);Float F=f;System.out.println(float f=+f);System.out.println(Float F=+F);Double D=d;System.out.println(double d=+d);System.out.println(Double D=+D);练习 10:public class CommandArgTest public static void main(String args)System.out.println(args0=+args0);System.out.println(args1=
13、+args1);System.out.println(args2=+args2);练习 11:public class Rainbow public static void main(String args)AllTheColorsOfTheRainbow atc=new AllTheColorsOfTheRainbow();System.out.println(atc.anIntegerRepresentingColors=+atc.anIntegerRepresentingColors);atc.changeColor(7);atc.changeTheHueOfTheColor(77);S
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 编程 思想 课后 习题 答案
限制150内