《Java程序设计案例教程》考试卷A答案.docx
-
资源ID:76456133
资源大小:11.32KB
全文页数:3页
- 资源格式: DOCX
下载积分:15金币
快捷下载
![游客一键下载](/images/hot.gif)
会员登录下载
微信登录下载
三方登录下载:
微信扫一扫登录
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
《Java程序设计案例教程》考试卷A答案.docx
Java程序设计案例教程考试卷A答案()略 (二)import java.util.Scanner;public class QuestionA2 public static void main(String) args) Scanner sc = new Scanner(System.in);System.out.print("输入圆的半径:");double radius = sc.nextDouble();圆的周长:"+ 2 * Math.PI * radius);(“圆的面积:"+ Math.PI * Math.pow(radius, 2); ) (三)import java.util.Scanner;public class QuestionA3 public static void main(String args) Scanner sc = new Scanner(System.in);String s;int year;do("输入年份:”);year = sc.nextlnt();iffyear % 4 = 0 && year % 100 != 0 11 year % 400 = 0) System.out.println(year + "是闰年");elseSystem.out.println(year + "不是闰年");("继续输入年份吗? (y/n)");s = sc.next();while(s.equalslgnoreCase("yH); )(四)public class Cuboid 长方体private double length, width, height;/fes 宽、高public Cuboid(double length, double width, double height) 构造方法if(length > 0 && width > 0 && height > 0) this.length = length;this.width = width; this.height = height;elseSystem.exit(O);)public double getLength() return length;)public void setLength(double length) this.length = length;)public double getWidth) return width;)public void setWidth(double width) this.width = width;)public double getHeightf) return height;)public void setHeightfdouble height) this.height = height;public double calSArea() /计算表面积return 2 * (length * width + width * height + height * length); )public double calVolume() 计算体枳 return length * width * height;)(五)public class Cube extends Cuboid (/正方体private double side;边长public Cube(double side) 构造方法super(side,side,side);public double getSide() return side;)public void setSide(double side) this.side = side;)public double calSArea() 计算表面枳return 6 * Math.pow(side, 2); )public double calVolumef) /计算体积return Math.pow(side, 3); ) )(六)import java.util.Arrays;public class QuestionA6 public static void main(String args) int myArray = 12, 29, 7, 35, 18, 2, 81, 65);int myArrayC = myArray.clone。;复制原数组Arrays.sort(myArrayC);("最大值和最小值的差为:”+ (myArrayCmyArrayC.length - 1- myArrayCO);) )(七)public class QuestionA7 extends Thread public void run() try(for(int i = l;i <= 10;i+)System.out.println(int)(Math.random() * 100); sleep(lOOO);)catch(lnterruptedException ie) ie.printStackTrace();)public static void main(String args) QuestionA7 qa7 = new QuestionA7();qa7.start();)(八)import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.Scanner;import mons.codec.digest.DigestUtils;加密组件包public class QuestionA8 public static void main(String args) Scanner sc = new Scanner(System.in);("请输入用户名:");String name = sc.next();("请输入密码:");String password = sc.next();try(Class.forName("com.mysql.jdbc. Driver");catch(ClassNotFoundException ce)System.out.println(ce);)try( Connectioncon=DriverManager.getConnection("jdbc:mysql:/localhost:330myDatabase", "root", "mysql"); PreparedStatement ps = con.prepareStatement("select * from account where name = ?");ps.setStringtl, name);ResultSet rs = ps.executeQuery();if(rs.next()if(DigestUtils.md5Hex(password).equals(rs.getString("password")/ 用户密码摘要处理("欢迎访问数据库!");else("密码不正确!");else("用户不存在!");rs.closed;ps.close();con.close();catch(SQLException ce)System.out.println(ce);)