欢迎来到天天文库
浏览记录
ID:58820614
大小:23.33 KB
页数:13页
时间:2020-10-25
《java语言程序设计(基础篇)第二章程序练习题答案.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、2.1(将摄氏温度转化为华氏温度)importjava.util.*;publicclasstest{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannerinput=newScanner(System.in);System.out.print("Enteradegreeincelsius:");doubleCelsius=input.nextDouble();doubleFahrenheit;Fahrenheit=(9.0/5)*Celsius+32;System.out.println
2、(Celsius+"Celsiusis"+Fahrenheit+"Fahrenheit");}}2.2(计算圆柱体的体积)importjava.util.*;publicclasstest{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannerinput=newScanner(System.in);System.out.print("Entertheradiusandlengthofacylinder:");doubleradius=input.nextDouble();doublelen
3、gth=input.nextDouble();doublearea=radius*radius*Math.PI;doublevolume=area*length;System.out.println("Theareais"+area);System.out.println("Thevolumeis"+volume);}}2.3(将英尺转换为米)importjava.util.Scanner;publicclasstest{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannerinput=n
4、ewScanner(System.in);System.out.print("Enteravalueforfeet:");doublefeet=input.nextDouble();doublemeters=feet*0.305;System.out.println(feet+"feetis"+meters+"meters");}}2.4(将磅转换为千克)importjava.util.Scanner;publicclasstest{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScanneri
5、nput=newScanner(System.in);System.out.print("Enteranumberinpounds:");doublepounds=input.nextDouble();doublekilograms=pounds*0.454;System.out.println(pounds+"poundsis"+kilograms+"kilograms");}}2.5(财务应用程序:计算消费)importjava.util.Scanner;publicclasstest{publicstaticvoidmain(String[]args){//TODOAut
6、o-generatedmethodstubScannerinput=newScanner(System.in);System.out.print("Enterthesubtotalandgratuityrate:");doublesubtotal=input.nextDouble();doubleGratuity=input.nextDouble();doublegratuity=subtotal*Gratuity*0.01;doubletotal=gratuity+subtotal;System.out.println("Thegratuityis$"+gratuity+"a
7、ndtotalis"+total);}}2.6(求一个整数个位数的和)importjava.util.Scanner;publicclasstest{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannerinput=newScanner(System.in);System.out.print("Enteranumberbetween0and1000:");intnumber=input.nextInt(
此文档下载收益归作者所有