《《Java程序设计案例教程》考试卷A答案.docx》由会员分享,可在线阅读,更多相关《《Java程序设计案例教程》考试卷A答案.docx(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、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.Sca
2、nner;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()
3、;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 getLe
4、ngth() 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() /计
5、算表面积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 setSi
6、de(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
7、= 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(
8、);)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;加密
9、组件包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=DriverManage
10、r.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);)