【作业】第九章课后作业
发布日期:2021-06-29 19:44:04
浏览次数:3
分类:技术文章
本文共 1116 字,大约阅读时间需要 3 分钟。
选择题:
1-10:B B ABD A B A CD A BD C 11-12:C A简答题:
1.Math.round(11.5) = 12,Math.round(-11.5) = -11。该方法为取整,四舍五入的原理是在参数上加0.5然后进行下取整。 2. int是基本类型,Integer是int的包装类。int不能为null,Integer可以为null,说明Integer是对象。 3.不可以,因为String类有final修饰符,而final修饰的类是不能被继承的,实现细节不允许改变。程序设计:
1./***************************** 文件名:[题目]* 作者:〈漆黑〉* 描述:〈 第九章课后作业 〉* 创建时间:2019.1.18****************************/import java.util.Scanner;public class Test { public static void main(String args){ Scanner scanner = new Scanner(System.in); System.out.print("请输入一个三位数:"); NarNum narNum = new NarNum(scanner.nextInt());//new一个水仙花数的对象 if(narNum.isNarNum())System.out.println("是水仙花数。");//判断返回的是真还是假 else System.out.println("不是水仙花数。"); } public static class NarNum{ //水仙花数类 private int a, b, c;//存储个位,十位,百位 private int x;//存储这个数 public NarNum(int x) { //构造函数 this.x = x; if(x >= 100 && x < 1000) { this.a = x % 10; this.b = (x / 10) % 10; this.c = (x / 100) % 10; } } public boolean isNarNum() { //判断是否是水仙花数的方法 if(Math.pow(a, 3)+ Math.pow(b, 3) + Math.pow(c, 3) == x && x!= 0) return true; return false; } }}
转载地址:https://darkness.blog.csdn.net/article/details/104028901 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年05月01日 01时51分14秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
第8章 NSArrayController
2019-04-30
第9章 NSUndoManager
2019-04-30
第10章 Archiving
2019-04-30
第11章 Basic Core Data
2019-04-30
第12章 Nib Files and NSWindowController
2019-04-30
第13章 User Defaults
2019-04-30
第14章 Using Notifications
2019-04-30
第17章 custom views
2019-04-30
第18章 Images and Mouse Events
2019-04-30
第21章 Pasteboards and Nil-Targeted Actions
2019-04-30
第22章 Categories
2019-04-30
第24章 NSTimer
2019-04-30
第26章 Creating NSFormatters
2019-04-30
第29章 View Swapping
2019-04-30
iphone开发学习资源
2019-04-30
第2章 Model View Controller
2019-04-30
“老外学中文“-开发进度
2019-04-30
我的mac pro,今后我们要一起加油啦!
2019-04-30
Huffman编码
2019-04-30