Teach Yourself Java 2 in 21 Days 书中样例代码实践

找了好几书JAVA的书,看了几章,都看不下去。

我觉得适合《Teach Yourself Java 2 in 21 Days》(Rogers Cadenhead Laura Lemay)还是适合我的。

孙卫琴那本,我感觉就罗嗦多了没到我点子上。

接口,抽象类这些内容讲得通俗易懂,看着不费力。

代码:

 1 class VolcanoRobot {
 2     String status;
 3     int speed;
 4     float temperature;
 5 
 6     void checkTemperature() {
 7         if (temperature > 660) {
 8             status = "returning home.";
 9             speed = 5;
10         }
11     }
12 
13     void showAttributes() {
14         System.out.println("Status: " + status);
15         System.out.println("Speed: " + speed);
16         System.out.println("Temperature: " + temperature);
17     }
18 }

 

 1 class VolcanoApplication {
 2     public static void main(String[] arguments) {
 3         VolcanoRobot dante = new VolcanoRobot();
 4         dante.status = "exploring";
 5         dante.speed = 2;
 6         dante.temperature = 510;
 7 
 8         dante.showAttributes();
 9         System.out.println("Increasing speed to 3.");
10         dante.speed = 3;
11         dante.showAttributes();
12         System.out.println("Changing temperature to 670.");
13         dante.temperature = 670;
14         dante.showAttributes();
15         System.out.println("Checking the temperature.");
16         dante.checkTemperature();
17         dante.showAttributes();
18     }
19 }

 

运行:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值