java第二章复习_《Java语言程序设计:基础篇》课后复习题答案-第二章

Chapter2Elementary Programming

1.Valid identifiers:applet,Applet,$4,apps,x,y,

radius

Invalid identifiers:a++,--a,4#R,#44,class,public, int

Keywords:

class,public,int

2.double miles=100;

final double KILOMETERS_PER_MILE= 1.609;

double kilometers=KILOMETERS_PER_MILE*miles;

System.out.println(kilometers);

The value of kilometers is160.9.

3.There are three benefits of using constants:(1)

you don’t have to repeatedly type the same value;(2)

the value can be changed in a single location,if

necessary;(3)the program is easy to read.

final int SIZE=20;

4.

a=46/9;=>a=5

a=46%9+4*4-2;=>a=1+16–2=15

a=45+43%5*(23*3%2);=>a=45+3*(1)=48

a%=3/a+3;=>a%=3+3;a%=6=>a=a%6=1;

d=4+d*d+4;=>4+ 1.0+4=9.0

d+= 1.5*3+(++a);=>d+= 4.5+2;d+= 6.5;=>d=7.5

d-= 1.5*3+a++;=>d-= 4.5+1;=>d=1– 5.5=-4.5

5.

2

2

-4

-4

1

6.(2+100)%7= 4.So it is Thursday.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值