




免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验九:工具类一(验证性 2学时)1掌握封装类的用法阅读如下程序并运行之,体会封装类的意义及相关用法:public class fuzhuang public static void main(String args) int i1=10;float f1=3.14f;double d1=3.1415926;Integer I1=new Integer(i1);/生成Integer类Float F1=new Float(f1);/生成Float类Double D1=new Double(d1); /生成Double类 String si1=I1.toString();/分别调用包装类的toString()方法转换为字符串String sf1=F1.toString();String sd1=D1.toString();System.out.println(si1+si1);System.out.println(sf1+sf1);System.out.println(sd1+sd1); 2 掌握使用Math类的用法定义名为numberplay的类,在main方法中,定义一个double类型变量num1,初始化为34.7889定义一个变量num2并初始化为36.0.使用相应方法计算num2的平方根。使用Math.round(num1)计算最接近num1的整数.,使用判断两者之间的较大值3)编写应用程序,定义一个一维数组(12个元素)并随机赋值,排序后输出,要求每行输出4个数4)编写应用程序,定义一个二维数组并赋值,显示二维数组每行的元素值,并求所有元素的和并输出。5编写应用程序,定义一个44的二维数组并随机赋值,按行列输出,求最外圈之和,求主对角线中最大值及位置。5) 研究下述程序,体会向量import java.util.*;public class testvector public static void main(String args) Vector myvector1=new Vector(1); System.out.println(myvector1.capacity(); myvector1.addElement(hello); myvector1.addElement(java); System.out.println(myvector1.capacity(); System.out.println(myvector1); String s1=(String )myvector1.elementAt(1); System.out.println(s1); Vector myvector=new Vector(); for(int i=0;i3;i+) myvector.addElement(welcome); myvector.addElement(to); myvector.addElement(beijing); System.out.println(myvector.size(); for(int i=0;imyvector.size();i+) String s=(String )myvector.elementAt(i); System.out.print(s+ ); System.out.println(); while(myvector.removeElement(to); for(int i=0;imyvector.size();i+) String s=(String )myvector.elementAt(i); System.out.println(s); 6研究下述程序,体会数组和向量的不同用法。/ AssignGrade.java: Assign gradepublic class AssignGrade / Main method public static void main(String args) int numOfStudents = 0; / The number of students int scores; / Array scores int best = 0; / The best score char grade; / The grade / Get number of students System.out.println(Please enter number of students); numOfStudents = MyInput.readInt(); / Create array scores scores = new intnumOfStudents; / Read scores and find the best score System.out.println(Please enter + numOfStudents + scores); for (int i=0; i best) best = scoresi; / Assign and display grades for (int i=0; i= best - 10) grade = A; else if (scoresi = best - 20) grade = B; else if (scoresi = best - 30) grade = C; else if (scoresi = best - 40) grade = D; else grade = F; System.out.println(Student + i + score is + scoresi + and grade is + grade); / AssignGradeUsingVector.java: Assign gradeimport java.util.*;public class AssignGradeUsingVector / Main method public static void main(String args) Vector scoreVector = new Vector(); / Vector to hold scores double best = 0; / The best score char grade; / The grade / Read scores and find the best score System.out.println(Please enter scores. + A negative score terminates input.); do System.out.print(Please enter a new score: ); double score = MyInput.readDouble(); if (score best) best = score; while (true); System.out.println(There are total + scoreVector.size() + students ); / Assign and display grades for (int i=0; i= best - 10) grade = A; else if (score = best - 20) grade = B; else if (score = best - 30) grade = C; else if (score = best - 40) grade = D; else grade = F; System.out.println(Student + i + score is + score + and grade is + grade); / MyInput.java: Contain the methods for reading int, double, and/ string values from the keyboardimport java.io.*;public class MyInput / Read a string from the keyboard public static String readString() BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1); / Declare and initialize the string String string = ; / Get the string from the keyboard try string = br.readLine(); catch (IOException ex) System.out.println(ex); / Return the string obtained from the keyboard return string; / Read an int value from the keyboard public static int readInt() return Integer.parseInt(readString(); / Read a double value from the keyboard public static double readDouble() return Double.parseDouble(readString(); / Read a byte value from the keyboard public static byte readByte() return Byte.parseByte(readString(); / Read a short value from the keyboard public static short readShort() return Short.parseShort(readStrin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小学一年级语言表达训练习题集
- 小学心理健康教育案例与实践指导
- 全国高中数学理科真题解析2022
- 医疗氧气吸入操作规范指南
- 大学生职业生涯规划期末大作业模板
- 高校教师教学质量反馈机制
- 提高团队协作效果助力团队发展
- 公司员工福利激励管理方法
- 企业发展策略在企业管理中的应用
- 农村土地资源管理和流转制度改革
- 货款对抵协议书
- 医学决定水平核心解读
- 原始股入股协议书合同
- 脱硫脱硝安全培训课件
- 医院医疗质量与安全管理委员会会议记录
- 2025年成人高考《语文》强化训练:经典题型专项试题试卷
- 设备安装安全保障措施
- 医疗器械经营质量管理制度及工作程序-完整版
- 人工智能训练师(高级)职业技能鉴定参考题(附答案)
- 行政事业单位固定资产培训
- T-SXPFS 0005-2024 山西省转型贷款企业方案编制手册(试行)
评论
0/150
提交评论