JAVA编程思想课后习题答案Word文档下载推荐.docx
- 文档编号:19335705
- 上传时间:2023-01-05
- 格式:DOCX
- 页数:14
- 大小:16.88KB
JAVA编程思想课后习题答案Word文档下载推荐.docx
《JAVA编程思想课后习题答案Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《JAVA编程思想课后习题答案Word文档下载推荐.docx(14页珍藏版)》请在冰豆网上搜索。
}
}
ATypeNamea=newATypeName();
a、i=3;
a、d=2、71828;
a、b=false;
a、show();
练习4:
publicclassDataOnlyTest{
classDataOnly{
DataOnlydata=newDataOnly();
data、i=3;
data、d=2、71828;
data、b=false;
data、show();
练习5:
publicclassDOTest2{
data、i=234;
data、d=2、1234545;
data、b=true;
练习6:
publicclassStorageTest{
classStoreStuff{
intstorage(Strings){
returns、length()*2;
}
}
StoreStuffx=newStoreStuff();
System、out、println(x、storage("
hi"
));
练习7:
classStaticTest{
staticinti=47;
classIncrementable{
staticvoidincrement(){StaticTest、i++;
publicclassITest{
System、out、println("
StaticTest、i="
+StaticTest、i);
StaticTestst1=newStaticTest();
StaticTestst2=newStaticTest();
st1、i="
+st1、i);
st2、i="
+st2、i);
Incrementablesf=newIncrementable();
sf、increment();
Aftersf、increment()called:
"
st1、i="
st2、i="
Incrementable、increment();
AfterIncrementable、incrementcalled:
练习8:
publicclassOneStaticTest{
StaticTestst1=newStaticTest();
StaticTestst2=newStaticTest();
Incrementable、increment();
AfterIncrementable、increment()called:
st1、i=3;
Afterst1、i=3,"
CreateanotherStaticTest,st3、"
StaticTestst3=newStaticTest();
st3、i="
+st3、i);
练习9:
publicclassAutoboxTest{
booleanb=false;
charc='
x'
;
bytet=8;
shorts=16;
inti=32;
longl=64;
floatf=0、32f;
doubled=0、64;
BooleanB=b;
booleanb="
+b);
BooleanB="
+B);
CharacterC=c;
charc="
CharacterC="
+C);
ByteT=t;
bytet="
+t);
ByteT="
+T);
ShortS=s;
shorts="
+s);
ShortS="
+S);
IntegerI=i;
inti="
IntegerI="
+I);
LongL=l;
longl="
+l);
LongL="
+L);
FloatF=f;
floatf="
+f);
FloatF="
+F);
DoubleD=d;
doubled="
+d);
DoubleD="
+D);
练习10:
publicclassCommandArgTest{
args[0]="
+args[0]);
args[1]="
+args[1]);
args[2]="
+args[2]);
练习11:
publicclassRainbow{
AllTheColorsOfTheRainbowatc=newAllTheColorsOfTheRainbow();
atc、anIntegerRepresentingColors="
+atc、anIntegerRepresentingColors);
atc、changeColor(7);
atc、changeTheHueOfTheColor(77);
Aftercolorchange,atc、anIntegerRepresentingColors="
atc、hue="
+atc、hue);
classAllTheColorsOfTheRainbow{
intanIntegerRepresentingColors=0;
inthue=0;
voidchangeTheHueOfTheColor(intnewHue){
hue=newHue;
intchangeColor(intnewColor){
returnanIntegerRepresentingColors=newColor;
练习12:
publicclassDocTest{
/**Entrypoingtoclass&
application、
*@paramargsarrayofstringarguments
*@throwsexceptionsNoexceptionsthrown
*/
Hello,it'
s:
System、out、println(newDate());
练习13-1:
publicclassDocumentation1{
/**Afieldcomment*/
publicinti;
/**Amethodcomment*/
publicvoidf(){}
2:
publicclassDocumentation2{
Dated=newDate();
voidshowDate(){
Date="
3:
publicclassDocumentation3{
Dated=newDate();
d="
练习14:
publicclassDocumentation4{
publicinti=2;
privateintj=3;
publicstaticvoidmain(String[]args){
Dated=newDate();
练习15:
publicclassHelloDocTest{
练习16:
classTree{
intheight;
Tree(){
Plantingaseedling"
height=0;
Tree(intinitialHeight){
height=initialHeight;
Creatingnewtreethatis"
+height+"
feettall"
voidinfo(){
Treeis"
voidinfo(Strings){
System、out、println(s+"
:
Treeis"
publicclassOverloading{
for(inti=0;
i<
5;
i++){
Treet=newTree(i);
t、info();
t、info("
overloadingmethod"
//Overloadedconstructor:
newTree();
第三章
publicclassPrintTest{
print("
Hello,fromshortform、"
P、rintln("
Hellofromgreggordonform、"
Hellofromlongform、"
classTube{
floatlevel;
publicclassAssign{
Tubet1=newTube();
Tubet2=newTube();
t1、level=0、9f;
t2、level=0、47f;
1:
t1、level:
+t1、level+"
t2、level:
+t2、level);
t1=t2;
t1、level=0、27f;
classBox{
floata;
publicclassPassObject2{
staticvoidf(Boxy){
y、a=2、71828f;
Boxx=newBox();
x、a=3、1416f;
x、a="
+x、a);
f(x);
classVelocityCalculator{
staticfloatvelocity(floatd,floatt){
if(t==0)return0f;
elsereturnd/t;
}
publicclassVelocityTester{
floatd=565、3f;
floatt=3、6f;
Distance:
Time:
floatv=VelocityCalculator、velocity(d,t);
Velocity:
+v);
classDog{
Stringname;
Stringsays;
voidsetName(Stringn){
name=n;
voidsetSays(Strings){
says=s;
voidshowName(){
P、rintln(name);
voidspeak(){
P、rintln(says);
publicclassDogTest{
Dogspot=newDog();
spot、setName("
Spot"
spot、setSays("
Ruff!
Dogscruffy=newDog();
scruffy、setName("
Scruffy"
scruffy、setSays("
Wurf!
spot、showName();
spot、speak();
scruffy、showName();
scruffy、speak();
publicclassDogCompare{
Dogbutch=newDog();
butch、setName("
Butch"
butch、setSays("
Hello!
butch、showName();
butch、speak();
Comparison:
spot==butch:
+(spot==butch));
spot、equals(butch):
+spot、equals(butch));
butch、equals(spot):
+butch、equals(spot));
Nowassign:
spot=butch"
spot=butch;
Compareagain:
+(spot==butch
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JAVA 编程 思想 课后 习题 答案