Java大学基础教程(英文第六版)课后第二章自测题答案.docx_第1页
Java大学基础教程(英文第六版)课后第二章自测题答案.docx_第2页
Java大学基础教程(英文第六版)课后第二章自测题答案.docx_第3页
Java大学基础教程(英文第六版)课后第二章自测题答案.docx_第4页
Java大学基础教程(英文第六版)课后第二章自测题答案.docx_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

package my.p2;import java.util.Scanner;public class Practice public static void main(String args) / 2.14ASystem.out.println(习题2.14答案);System.out.println(1 2 3 4);/ 2.14BSystem.out.print(1 );System.out.print(2 );System.out.print(3 );System.out.print(4);/ 2.14CSystem.out.printf(n%d %d %d %d, 1, 2, 3, 4); / % 格式说明符,后接数据类型/ 2.15:import firstSystem.out.print(n习题2.15答案(提示:类似SelfTest2_5.java));Scanner input = new Scanner(System.in);int n1, n2, products, quotients, sums, differences;System.out.print(ninput the first integer:n);n1 = input.nextInt();System.out.print(input the second integer:n);n2 = input.nextInt();sums = n1 + n2;differences = n1 - n2;products = n1 * n2;quotients = n1 / n2;System.out.printf(the four operations(+ - /) outcomes are %d %d %d %d, sums,differences, products, quotients);/ 2.16System.out.print(nn习题2.16答案n);System.out.printf(The numbers are %d and %d, n1, n2);if (differences 0)System.out.printf(nnThe larger is n1= %dn, n1);if (differences n3)min = n3;if (n3 n1)max = n3;System.out.printf(nThe maximum number is %d , and the minimum number is %d,max, min);/ 2.18System.out.print(n习题2.18答案n);System.out.print(nthe quadrate is n);System.out.printf(*n* *n* *n* *n* *n* *n* *n* *n* *n*n);System.out.print(nthe ellipse is n);System.out.printf( * n * * n* *n* *n* *n* *n* *n* *n * * n * n);System.out.print(nthe arrow is n);System.out.printf( * n * n * n * n * n * n * n * n * n * n);System.out.print(nthe rhombus is n);System.out.printf( * n * n * * n * * n* *n * * n * * n * n * n);/ pentagam/ System.out.print(n)/ 2.19System.out.print(n习题2.19答案n);System.out.println(*n*n*n*n*);/ 2.20-23略,2.24略/ 2.25System.out.print(n习题2.25答案n);int n4, testn;System.out.print(n输入一个5位整数n);n4 = input.nextInt();testn = n4 % 2;if (testn = 0)System.out.printf(n%d is 偶数n, n4);if (testn != 0)System.out.printf(n%d is 奇数n, n4);/ 2.26System.out.print(n习题2.26答案n);int testnn;testnn = n1 % n2;if (testnn = 0)System.out.printf(n%d is %d 的倍数n, n1, n2);if (testnn != 0)System.out.printf(n%d isnt %d 的倍数n, n1, n2);/ 2.28System.out.print(n习题2.26答案n);int r = n3;double di, ci, ar;di = 2 * r;ci = 2 * Math.PI * r;ar = Math.PI * r * r;System.out.printf(nThe diameter of the circle is %f;nthe perimeter of the circle is %f;nand the area of the circle is %fn,di, ci, ar); / %f 不能写成%d/ 2.29System.out.print(n习题2.29测试n);System.out.printf(The character of %c has the value %dn, A,(int) A);System.out.printf(The character of %c has the value %dn, B,(int) B);System.out.printf(The character of %c has the value %dn, C,(int) C);System.out.printf(The character of %c has the value %dn, a,(int) a);System.out.printf(The character of %c has the value %dn, b,(int) b);System.out.printf(The character of %c has the value %dn, c,(int) c);System.out.printf(The character of %c has the value %dn, 0,(int) 0);System.out.printf(The character of %c has the value %dn, 1,(int) 1);System.out.printf(The character of %c has the value %dn, 2,(int) 2);System.out.printf(The character of %c has the value %dn, $,(int) $);System.out.printf(The character of %c has the value %dn, *,(int) *);System.out.printf(The character of %c has the value %dn, +,(int) +);System.out.printf(The character of %c has the value %dn, /,(int) /);/ 2.30System.out.print(n习题2.30答案n);System.out.print(n 查看n4n);System.out.printf(The character of %d divided into the value %d %d %d %d %d,n4, (n4 - n4 % 10000) / 10000),(n4 % 10000 - n4 % 10000 % 1000) / 1000),(n4 % 1000 - n4 % 100) / 100,(n4 % 100 - n4 % 10) / 10, n4 % 10);/2.31System.out.print(n习题2.30答案n);System.out.printf(%st%st%sn,number,square,cube);System.out.printf(%st%st%sn,0,0,0);System.out.printf(%st%st%sn,1,1,1);System.out.printf(%st%st%sn,2,4,8);System.out.printf(%st%st%sn,3,9,27);System.out.printf(%st%st%sn,4,16,64);System.out.printf(%st%st%sn,5,25,1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论