




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Java编程思想(第四版)习题答案第二章练习1:public class PrimitiveTest static int i;static char c;public static void main(String args) "int = " + i);"char = " + c);练习2:public class HelloWorld public static void main(String args) "Hello World!");练习3:public class ATNTest public static void m
2、ain(String args) class ATypeName int i;double d;boolean b;void show() ATypeName a = new ATypeName(); = 3; = ; = false;();练习4:public class DataOnlyTest public static void main(String args) class DataOnly int i;double d;boolean b;void show() DataOnly data = new DataOnly(); = 3; = ; = false;();练习5:publ
3、ic class DOTest2 public static void main(String args) class DataOnly int i;double d;boolean b;void show() DataOnly data = new DataOnly(); = 234; = ; = true;();练习6:public class StorageTest public static void main(String args) class StoreStuff int storage(String s) return () * 2;StoreStuff x = new Sto
4、reStuff();"hi");练习7:class StaticTest static int i = 47;class Incrementable static void increment() +; public class ITest public static void main(String args) "= " + ;StaticTest st1 = new StaticTest();StaticTest st2 = new StaticTest();"= " + ;"= " + ;Incrementa
5、ble sf = new Incrementable();();"After () called: ");" = " + ;" = " + ;();"After called: ");" = " + ;" = " + ;练习8:class StaticTest static int i = 47;class Incrementable static void increment() +; public class OneStaticTest public static voi
6、d main(String args) "= " + ;StaticTest st1 = new StaticTest();StaticTest st2 = new StaticTest();"= " + ;"= " + ;();"After () called: ");" = " + ;" = " + ;();"After called: ");" = " + ;" = " + ; = 3;"After
7、= 3, ");" = " + ;" = " + ;"Create another StaticTest, st3.");StaticTest st3 = new StaticTest();" = " + ;练习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;
8、float f = ;double d = ;Boolean B = b;"boolean b = " + b); "Boolean B = " + B); Character C = c;"char c = " + c);"Character C = " + C);Byte T = t;"byte t = " + t);"Byte T = " + T);Short S = s;"short s = " + s);"Short S = "
9、; + S);Integer I = i;"int i = " + i);"Integer I = " + I);Long L = l;"long l = " + l);"Long L = " + L);Float F = f;"float f = " + f);"Float F = " + F);Double D = d;"double d = " + d);"Double D = " + D);练习10:public class C
10、ommandArgTest public static void main(String args) "args0 = " + args0);"args1 = " + args1);"args2 = " + args2);练习11:public class Rainbow public static void main(String args) AllTheColorsOfTheRainbow atc = new AllTheColorsOfTheRainbow();" = " + ;(7);(77);"
11、After color change, = " + ;" = " + ;class AllTheColorsOfTheRainbow int anIntegerRepresentingColors = 0;int hue = 0;void changeTheHueOfTheColor(int newHue) hue = newHue;int changeColor(int newColor) return anIntegerRepresentingColors = newColor;练习12:public class DocTest /* Entry poing
12、to class & application.* param args array of string arguments* throws exceptions No exceptions thrown*/public static void main(String args) "Hello, it's: "); Date();练习13-1:public class Documentation1 /* A field comment */public int i;/* A method comment */public void f() 2:public c
13、lass Documentation2 Date d = new Date();void showDate() "Date = " + d);3:public class Documentation3 public static void main(String args) Date d = new Date();"d = " + d);练习14:public class Documentation4 public int i = 2;private int j = 3;public static void main(String args) Date
14、d = new Date();"d = " + d);练习15:public class HelloDocTest public static void main(String args) "Hello World!");练习16:class Tree int height;Tree() "Planting a seedling");height = 0;Tree(int initialHeight) height = initialHeight;"Creating new tree that is " + hei
15、ght + " feet tall");void info() "Tree is " + height + " feet tall");void info(String s) + ": Tree is " + height + " feet tall");public class Overloading public static void main(String args) for(int i = 0; i < 5; i+) Tree t = new Tree(i);();("
16、overloading method");("Hello from greggordon form.");"Hello from long form.");练习2:class Tube float level;public class Assign public static void main(String args) Tube t1 = new Tube();Tube t2 = new Tube(); = ; = ;("1: : " + + ", : " + ;t1 = t2;("2: :
17、" + + ", : " + ; = ; ("3: : " + + ", : " + ;练习3:class Box float a;public class PassObject2 static void f(Box y) = ;public static void main(String args) Box x = new Box(); = ;print("1: = " + ;f(x);print("2: = " + ;练习4:class VelocityCalculator sta
18、tic 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 = ;float t = ;"Distance: " + d);"Time: " + t);float v = (d, t);"Velocity: " + v);练习5:class Dog String name;String says;voi
19、d setName(String n) name = n;void setSays(String s) says = s;void showName() (name);void speak() (says);public class DogTest public static void main(String args) Dog spot = new Dog();("Spot");("Ruff!");Dog scruffy = new Dog();("Scruffy");("Wurf!");();();(); ();练习6:class Dog String name;String says;void setName(String n) name = n;void setSays(String s) says = s;void showName() (name);void speak() (says);public
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 商丘市梁园区2025-2026学年数学四上期末调研模拟试题含解析
- 2025年潍坊市青州市数学四上期末综合测试模拟试题含解析
- 中职计算机应用基础教案课件版
- 2026届和龙市六年级数学第一学期期末监测模拟试题含解析
- 山西省吕梁市方山县实验小学2025年数学四上期末质量检测试题含解析
- 2026届广东省梅州市兴宁市六年级数学第一学期期末达标检测模拟试题含解析
- 2026届云南省昭通市大关县数学六上期末考试模拟试题含解析
- 财务会计试用期工作总结
- 2026届吉林省松原市扶余县六年级数学第一学期期末经典模拟试题含解析
- 智能化产品开发-洞察及研究
- 高职院校高水平现代物流管理专业群建设方案(现代物流管理专业群)
- DLT 572-2021 电力变压器运行规程
- DL∕T 491-2008 大中型水轮发电机自并励励磁系统及装置运行和检修规程
- 2024年辅警招聘考试试题库及参考答案【b卷】
- 白龙江引水工程环境影响报告书(公示版)
- 2024抢救过敏性休克课件
- JB T 8315-2007变压器用强迫油循环风冷却器
- 【幼儿自主游戏中教师支持策略研究(论文)11000字】
- FluorPen-FP-110植物荧光测量仪中文说明书
- 模拟电路试卷及答案(十套)及模拟电路基础知识教程
- 娄敬山制灰用灰岩矿资源量核实报告
评论
0/150
提交评论