皮皮学,免费搜题
登录
logo - 刷刷题
搜题
【简答题】
上机实践 7 字符串 、时间与数字 请注意:此次实验请注意使用 Java API 官方文档,链接: Java TM Platform Standard Edition 6 中文版: http://tool.oschina.net/apidocs/apidoc?api=jdk-zh Oracle 官方 Java TM Platform Standard Edition 9 英文版(最新): https://docs.oracle.com/javase/9/docs/api/ 实验 1 String 类的常用方法 模板代码 StringExample.java class StringExample { public static void main(String args[]) { String s1=new String("you are a student"), s2=new String("how are you"); if( 【代码 1 】 ) // 使用 equals 方法判断 s1 与 s2 是否相同 { System.out.println("s1 与 s2 相同 "); } else { System.out.println("s1 与 s2 不相同 "); } String s3=new String("22030219851022024"); if( 【代码 2 】 ) // 判断 s3 的前缀是否是“ 220302 ”。 { System.out.println(" 吉林省的身份证 "); } String s4=new String(" 你 "), s5=new String(" 我 "); if( 【代码 3 】 )// 按着字典序 s4 大于 s5 的表达式。 { System.out.println(" 按字典序 s4 大于 s5"); } else { System.out.println(" 按字典序 s4 小于 s5"); } int position=0; String path="c:\\java\\jsp\\A.java"; position= 【代码 5 】 // 获取 path 中最后出现目录分隔符号的位置 System.out.println("c:\\java\\jsp\\A.java 中最后出现 \\ 的位置 :"+position); String fileName= 【代码 6 】 // 获取 path 中“ A.java ”子字符串。 System.out.println("c:\\java\\jsp\\A.java 中含有的文件名 :"+fileName); String s6=new String("100"), s7=new String("123.678"); int n1= 【代码 7 】 // 将 s6 转化成 int 型数据。 double n2= 【代码 8 】 // 将 s7 转化成 double 型数据。 double m=n1+n2; System.out.println(m); String s8= 【代码 9 】 //String 调用 valuOf(int n) 方法将 m 转化为字符串对象 position=s8.indexOf("."); String temp=s8.substring(position+1); System.out.println(" 数字 "+m+" 有 "+temp.length()+" 位小数 ") ; String s9=new String("ABCDEF"); char a[]= 【代码 10 】 // 将 s8 存放到数组 a 中。 for(int i=a.length-1;i>=0;i--) { System.out.print(" "+a[i]); } } } 请将代码补充完整,并将运行结果截图写入实验报告。 实验 2 比较日期的大小 模板代码 DateExample import java.util.*; import javax.swing.JOptionPane; public class DateExample { public static void main(String args[ ]) { String str=JOptionPane.showInputDialog(" 输入第一个日期的年份 :"); int yearOne=Integer.parseInt(str); str=JOptionPane.showInputDialog(" 输入该年的月份 :"); int monthOne=Integer.parseInt(str); str=JOptionPane.showInputDialog(" 输入该月份的日期 :"); int dayOne=Integer.parseInt(str); str=JOptionPane.showInputDialog(" 输入第二个日期的年份 :"); int yearTwo=Integer.parseInt(str); str=JOptionPane.showInputDialog(" 输入该年的月份 :"); int monthTwo=Integer.parseInt(str); str=JOptionPane.showInputDialog(" 输入该月份的日期 :"); int dayTwo=Integer.parseInt(str); Calendar calendar= 【代码 1 】 // 初始化日历对象 【代码 2 】 // 将 calendar 的时间设置为 yearOne 年 monthOne 月 dayOne 日 long timeOne= 【代码 3 】 //calendar 表示的时间转换成毫秒 【代码 4 】 // 将 calendar 的时间设置为 yearTwo 年 monthTwo 月 dayTwo 日 long timeTwo= 【代码 5 】 //calendar 表示的时间转换成毫秒。 Date date1= 【代码 6 】 // 用 timeOne 做参数构造 date1 Date date2= 【代码 7 】 // 用 timeTwo 做参数构造 date2 if(date2.equals(date1)) { System.out.println(" 两个日期的年、月、日完全相同 "); } else if(date2.after(date1)) { System.out.println(" 您输入的第二个日期大于第一个日期 "); } else if(date2.before(date1)) { System.out.println(" 您输入的第二个日期小于第一个日期 "); } long days= 【代码 8 】 // 计算两个日期相隔天数 System.out.println(yearOne+" 年 "+monthOne+" 月 "+dayOne+" 日和 " +yearTwo+" 年 "+monthTwo+" 月 "+dayTwo+" 相隔 "+days+" 天 "); } } 请将代码补充完整,并将运行结果截图写入实验报告。 实验 3 处理大整数 模板代码 BigintegerExample import java.math.*; class BigIntegerExample { public static void main(String args[]) { BigInteger n1=new BigInteger("987654321987654321987654321"), n2=new BigInteger("123456789123456789123456789"), result=null; result= 【代码1】//n1和n2做加法运算 System.out.println(" 和:"+result.toString()); result= 【代码2】//n1和n2做减法运算 System.out.println(" 差:"+result.toString()); result= 【代码3】//n1和n2做乘法运算 System.out.println(" 积:"+result.toString()); result= 【代码4】//n1和n2做除法运算 System.out.println(" 商:"+result.toString()); BigInteger m=new BigInteger("1968957"), COUNT=new BigInteger("0"), ONE=new BigInteger("1"), TWO=new BigInteger("2"); System.out.println(m.toString()+" 的因子有:"); for(BigInteger i=TWO;i.compareTo(m)<0;i=i.add(ONE)) { if((n1.remainder(i).compareTo(BigInteger.ZERO))==0) { COUNT=COUNT.add(ONE); System.out.print(" "+i.toString()); } } System.out.println(""); System.out.println(m.toString()+" 一共有"+COUNT.toString()+"个因子"); } } 请将代码补充完整,并将运行结果截图写入实验报告。 练习 1 教材 220 页,第 4 题第 (3) 小题,请在实验报告中描述程序思路,并展示源代码和运行结果。 练习 2 教材 220 页,第 4 题第 (6) 小题,请在实验报告中描述程序思路,并展示源代码和运行结果。
手机使用
分享
复制链接
新浪微博
分享QQ
微信扫一扫
微信内点击右上角“…”即可分享
反馈
参考答案:
举一反三
【多选题】下列各组中药其原植物相同的有哪些
A.
板蓝根与大青叶
B.
瓜蒌与天花粉
C.
枳实与枳壳
D.
枸杞子与地骨皮
E.
桑葚与桑白皮
【多选题】正面传球需要注意的重点是()?
A.
稍蹲准备姿势
B.
手型成半球形
C.
击球点准确
D.
移动
【单选题】正面传球的手型是()?
A.
勺形
B.
半球形
C.
“一”字形
D.
“八”字形
【单选题】细菌细胞膜有诸多功能,但不包括( )。
A.
参与细胞呼吸过程
B.
细菌遗传物质的复制
C.
进行生物合成
D.
营养物质的摄取与代谢物的排出
E.
形成中介体
【单选题】6 (28 days to D-Day) May 9, 1944 Dearest, The invasion, I read, is a topic of daily conjecture among the people at home and I guess you are a bit worried. Well, sweetheart, don’t worry, please. It is ...
A.
I will not do it; God will.
B.
He believed it was God’s will whether they win or lose will not be determined by him, but by God.
C.
He believed it was God’s will whether he would be one of the assault troops and whether he would survive the fighting.
D.
The quaterback at preschool was a pious Christian.
【多选题】下列各组中药其原植物相同的有哪些()
A.
瓜蒌与天花粉
B.
板蓝根与大青叶
C.
金银花与忍冬藤
D.
桑叶与桑白皮
【单选题】一个人的生活实践对于社会和个人所具有的作用和意义是( )。
A.
人生价值
B.
人的价值
C.
自我价值
D.
生命价值
【多选题】零件图的标题栏中包括哪些内容
A.
材料
B.
绘图比例
C.
图样编号
D.
零件名称
【多选题】36 下列各组中药其原植物相同的有哪些
A.
兜铃与青木香
B.
蒌与天花粉
C.
实与枳壳
D.
杞子与地骨皮
E.
桑椹与桑白皮
【判断题】正面传球的传球手型不是半球形。
A.
正确
B.
错误
相关题目:
参考解析:
知识点:
题目纠错 0
发布
创建自己的小题库 - 刷刷题