耿祥义张跃平java大学实用教程编程题答案
习题解答
第一章作业题
1 pu icc ss el
ubl csta i void ma n ( tr ng args[ )
System o tpi tln(“早上好,goo Morning”)
}
2。
mport ja a ap l t。 import v awt。 p bl ic lass oy e tendsAp l t pu icvoi p int rap ) {g。 s tColor olo 。 blue)g。 dr w ing(”你好 hel lo" 12 30
}
第二章作业题
1 publ icclass Zuoe2_1{pub icst ticvoi main (Stri g r s ) ch c= а’
Sy t out prin n("字母 c+ 在 n ode表中的顺序位置 ” i t c);
Sy te。 out。 println("字母表 ;whi le c<=’я’
System out pri t ” "c);
耿祥义张跃平java大学实用教程编程题答案c= ar (c1
}
}
}
impor a uti l*;pu l ic class ZuoYe2_
c s a i v id ( tring rgs
cann r r ade =new anner(Syst i ;lo g chengj i= ;
nt =whi le ea er hasNext nt ) {int x= eade 。 xt nt( m=m1;
heng c ngj i*x;
Sys em。 ut。 p r n l (m+"个数的乘积为" h e g i);}
}
第三章作业题
import jav ut 。 *;
u l i c ass Zuo 3_1{
ubl cstat voi main Str ng ar s )
Scan re der=new a ner(Syst m in doubl y , 0;x=readernex Double )if x 〈0)y=-1+2*xels i 0)y=—1;else i (x0
-1+3x;
Sy em out r ntln(y
}
}
耿祥义张跃平java大学实用教程编程题答案
publ i classuYe3_2{pub icstaticvoi i (St i g arg [ ){
nts =0 =3,n7 a1w i le(a 〈=100 if a==0&a%n==0)
m= u+;a+
}
System out i ln "s m= + um }
}
3。pub ic classZ Ye3_3
publ ic sta ic vo d main St nga gs[ )
longsum=0,a , te=a n= i
or(i=1 <=n i++)
{ sum um+itemitem= t m*10a
Sy te ut。 i tln sum
}
4
u l icc a Zu e3_4
{
bl c static id ma ( ing rg ]{
blesum= a ,b=1 fuhao= , itea/b
n i=1whi le(i= 000)
su= um+f h oit m;i++;fu a =fu ao(-1 b= itema/b
耿祥义张跃平java大学实用教程编程题答案
System ut pri t n ” = + um }
}
5 publ class ZuoYe3_5
{p b ic ta i voi main String ar s {
lesum=0 a= ;in i1whi l (i<= 0
if(i〉 = 0)sum= mai+a=ai ;
Systemut。 rin l (”sum="+s )
第四章作业题
1
lass gCh int tar d;
Den Ch ( {
}
De gCh (int start nt d t s。 start= t rtthi d=;
void se Sta t in s){s r
耿祥义张跃平java大学实用教程编程题答案v id set(int ){
s。 d=d;
nt get (i n i t um= i= ;
hi le( <= sum=sum+ rtsta = tart+;i+;
}re urn m;
}p bl ic ass ZuoY_1
{p l icsta i vo d m in String r ]{
Dengha hul ie=ne Dengha(2,3);
Sy em out pri tln s l i g um 00) ; ul e s Start(1 shul ie s D();
Systemut p i tln( hul i ge um 9));
}
.clas Lett r publ c o rintLetter ){
or ch rc= ' c='z' ;c+)
Syst u ri nt(” ”+)
pub ic lass Zu 4_2
publ icstat cv i m i (String rg [ )
{
L t rp= w L te ()p printLetter(
耿祥义张跃平java大学实用教程编程题答案
3.class S areEquatio doublea b;stati doub e cdo ble oot1 oot2boole oo
ubl i Squ eE ua do bl a doubleb,double c th s。 a=a;
isb=;
S uare qu t on =cif a =0 {botrue
}else boo=f lse
}
u l i void g Roots
bo
Sys em out pri ln ”是一元次方程” ;doub skb 4*aci di k〉 )
oot1=(b+M h。 s r (disk ) *a root2= —a qr (disk /(2a
ys em。 o t 。 p r ntf("方程的根 f %f n",root1,root2 ;
else{
ysteou r ntf "方程没有实根\” ;
}
else{
Sys e ut ri tl ”不是一元2次方程”
pu l c voids Coefficie t double ,dou le b d ublec
耿祥义张跃平java大学实用教程编程题答案
his a=;
his。 b
Sq reEquat onc=c;i a =0){boo=true
}e se
o=false
p bl iccl sZ oe4_3{
ub ic st t cvoid ain Str ng gs[ {
Squar Eq a ion eq at n1 ew Square quatio 4,,1)
Sq reEquati uat n2new ua e ation 3 5 7 ;equ t on1 g tRots )
quation2 ge ot )
}
4
mport java。 u i l。 Scanner
lass A{i t f in m, ntn i m*n
{ System out。 rintl ( 有负数程序退出
yst m。 e it(0 ;
f( )
{ int temp=mm=;ntemp
nt a=,=;int =;whi le r!=0
=
=
耿祥义张跃平java大学实用教程编程题答案r=m;
}re rn n;
cl ss
A a
B )
=new A( ;
}intg in intn {in emp=a f m );
etur n/temp;
}
ub cla s uoYe44
pub icsta ic oi main String args[ ]
{
Scanner rea =new Scan r(S stem。 in
ystem out p i tl ”输入2个正整数程序计算出它们的最大公约数和最小公倍数");
Sy teut p int 输入第一个整数 "
nt m=r ader。 ex Int ;
yste。 t in (”输入第二个整数:” int n=rea er extInt
=ne
Bb=neB(
t mout。 r ntln(+ 和"+ +"的最大公约数是+a。 f m,n )
ystem o t println m+”和 n"的最小公倍数是 +b。 g(m,n));
im ort java。 applet pplet;
mpor jav awt。 *publ icc as am le10 exten s plet
耿祥义张跃平java大学实用教程编程题答案
ut redbutton;pu l ic voi i i (
r dbut on=new utt n "我是一个红色的按钮")r bu on e B ckgrou d Cl r e );r button s tF regro n Co orwhite);add r d utton)
}
第五章作业题
1 import v 。 uti l Sca ner
las A
publ i in f intm intn
{if(m<n
{int ep=mm=
ep
nt r=mn;whi l (r =0)
m=n
r;r=mn;
}
e u n n;
}
}class ext nds A
{publ c nt f(int m, intn
HostKvm 商家我们算是比较熟悉的国内商家,商家主要还是提供以亚洲数据中心,以及直连海外线路的服务商。这次商家有新增香港和俄罗斯两个机房的高防服务器方案。默认提供30GB防御,且目前半价优惠至4.25美元起步,其他方案的VPS主机还是正常的八折优惠。我们看看优惠活动。香港和俄罗斯半价优惠:2021fall,限购100台。通用优惠码:2021 ,八折优惠全部VPS。我们看看具体的套餐。1、香港高...
VoLLcloud LLC是一家成立于2020年12月互联网服务提供商企业,于2021年1月份投入云计算应用服务,为广大用户群体提供云服务平台,已经多个数据中心部署云计算中心,其中包括亚洲、美国、欧洲等地区,拥有自己的研发和技术服务团队。现七夕将至,VoLLcloud LLC 推出亚洲地区(香港)所有产品7折优惠,该产品为CMI线路,去程三网163,回程三网CMI线路,默认赠送 2G DDoS/C...
金山云618年中促销活动正在进行中!金山云针对企业级新用户优惠力度比普通个人用户优惠力度要大,所以我们也是推荐企业新用户身份购买金山云企业级云服务器,尽量购买3年配置的,而不是限时秒杀活动中1年的机型。企业级用户购买金山云服务器推荐企业专区:云服务器N3 2核4G云服务器,1-5M带宽,827.64元/3年,性价比高,性能稳定!点击进入:金山云618年中促销活动目前,金山云基础型E1云服务器2核4...