Java大学基础教程(英文第六版)课后第六章自测题答案

  • 格式:docx
  • 大小:60.33 KB
  • 文档页数:36

下载文档原格式

  / 36
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//test the 'Math' class

//Math class is a part of ng package, so no need to import it publicclass p217_6$3 {

/**

* @param args

*/

publicstaticvoid main(String[] args) {

// TODO Auto-generated method stub

System.out.printf("Math.abs( 23.7 ) = %s\n", Math.abs( 23.7 ) );

System.out.printf("Math.abs( 23.7 ) = %f\n", Math.abs( 23.7 ) );

System.out.printf("Math.abs( 0.0 ) = %f\n", Math.abs( 0.0 ) );

System.out.printf("Math.abs( -23.7 ) = %f\n", Math.abs( -23.7 ) );

System.out.printf("Math.ceil( 9.2 ) = %f\n", Math.ceil( 9.2 ) );

System.out.printf("Math.ceil( -9.8 ) = %f\n", Math.ceil( -9.8 ) );

System.out.printf("Math.cos( 0.0 ) = %f\n", Math.cos( 0.0 ) );

System.out.printf("Math.exp( 1.0 ) = %f\n", Math.exp( 1.0 ) );

System.out.printf("Math.exp( 2.0 ) = %f\n", Math.exp( 2.0 ) );

System.out.printf("Math.floor( 9.2 ) = %f\n", Math.floor( 9.2 ) );

System.out.printf("Math.floor( -9.8 ) = %f\n",

Math.floor( -9.8 ) );

System.out.printf("Math.log( Math.E ) = %f\n",

Math.log(Math.E ) );

System.out.printf("Math.log( Math.E * Math.E ) = %f\n",

Math.log(Math.E * Math.E ) );

System.out.printf("Math.max( 2.3, 12.7 ) = %f\n",

Math.max( 2.3, 12.7 ) );

System.out.printf("Math.max( -2.3, -12.7 ) = %f\n",

Math.max( -2.3, -12.7 ) );

System.out.printf("Math.min( 2.3, 12.7 ) = %f\n",

Math.min( 2.3, 12.7 ) );

System.out.printf("Math.min( -2.3, -12.7 ) = %f\n",

Math.min( -2.3, -12.7 ) );

System.out.printf("Math.pow( 2.0, 7.0 ) = %f\n",

Math.pow( 2.0, 7.0 ) );

System.out.printf("Math.pow( 9.0, 0.5 ) = %f\n",

Math.pow( 9.0, 0.5 ) );

System.out.printf("Math.sin( 0.0 ) = %f\n", Math.sin( 0.0 ) );

System.out.printf("Math.sqrt( 900.0 ) = %f\n",

Math.sqrt( 900.0 ) );

System.out.printf("Math.tan( 0.0 ) = %f\n", Math.tan( 0.0 ) );

}

}

import java.util.Scanner;

publicclass p218_6$6a {

/**

* @param args

*/

publicstaticvoid main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

System.out.print("input the radius of a sphere:\n");

double r = input.nextDouble();

p218_6$6b compute = new p218_6$6b();

//compute area

double area = puteArea(r);

System.out.printf("\nthe AREA of a sphere is: %f\n", area);

//compute volume

double volume = puteVolume(r);

System.out.printf("\nthe VOLUME of a sphere is: %f\n", volume);

}

}

publicclass p218_6$6b {

publicdouble computeArea(double r){

double area = Math.PI * Math.pow(r, 2) ;

return area;

}

publicdouble computeVolume(double r){

double volume = (4/3) * Math.PI * Math.pow(r, 3);

return volume;

}

}