欢迎来到天天文库
浏览记录
ID:16120314
大小:76.00 KB
页数:22页
时间:2018-08-08
《java程序设计教程(第六版)课后习题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、pp2.3publicclassfudian{publicstaticvoidmain(String[]args){floata=2.10f,b=3.70f;floatResult1,Result2,Result3;Result1=a+b;Result2=a-b;Result3=a*b;System.out.println("Result1is:"+Result1);System.out.println("Result2is:"+Result2);System.out.println("Result3is:"+Result3);}}2.4publicclassTempConverter{pu
2、blicstaticvoidmain(String[]args){finalintBASE=32;finaldoubleCONVERSION_FACTOR=5.0/9.0;doublecelsiusTemp;intfahrenheitTemp=70;//valuetoconvertcelsiusTemp=(fahrenheitTemp-BASE)*CONVERSION_FACTOR;System.out.println("FahrenheitEquivalent:"+fahrenheitTemp);System.out.println("CelsiusTemperature:"+celsiu
3、sTemp);}}2.5publicclassyinglizhuanqianmi{publicstaticvoidmain(String[]args){floatBase=1.60935f;floatQianmi;floatYingli=19.85f;Qianmi=Yingli*Base;System.out.println("YingLi:"+Yingli);System.out.println("QianMi:"+Qianmi);}}2.6publicclassTimeConverter1{publicstaticvoidmain(String[]args){intHour=5,Minu
4、te=35,Second=51;intSECONDS;SECONDS=Hour*60*60+Minute*60+Second;System.out.println(+Hour+"时"+Minute+"分"+Second+"秒");System.out.println("换算成秒:"+SECONDS);}}2.7publicclassTimeConverter2{publicstaticvoidmain(String[]args){intSECONDS=10853;intHour,Minute,Second;Second=SECONDS%60;Minute=(SECONDS-Second)%6
5、0;Hour=(SECONDS-Second-Minute*60)/3600;System.out.println(SECONDS+"秒,转化为");System.out.println(Hour+"时"+Minute+"分"+Second+"秒");}}2.9importjava.util.*;publicclassDollarbill{publicstaticvoidmain(String[]args){floatDollar1,Dollar2;intTen,Five,One,Quarters,Dimes,Nickles,Pennies;Scannerreader=newScanner(
6、System.in);System.out.println("输入币值:");Dollar1=reader.nextFloat();Dollar2=Dollar1*100;Pennies=(int)Dollar2%5;Nickles=((int)Dollar2%10-Pennies)/5;Dimes=((int)Dollar2-Pennies-Nickles*5)%50/10;Quarters=(int)Dollar2%100/50;One=((int)Dollar2-Pennies-Nickles*5-Dimes*10-Quarters*50)%500/100;Five=(int)Doll
7、ar2%1000/500;Ten=(int)Dollar2/1000;System.out.println(Ten+"tendollarbills");System.out.println(Five+"fivedollarbills");System.out.println(One+"onedollarbills");System.out.println(Quarters+"quartersdollarbil
此文档下载收益归作者所有