《Java程序设计案例教程》考试卷B答案.docx
-
资源ID:76454471
资源大小:11.21KB
全文页数:3页
- 资源格式: DOCX
下载积分:15金币
快捷下载
![游客一键下载](/images/hot.gif)
会员登录下载
微信登录下载
三方登录下载:
微信扫一扫登录
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
《Java程序设计案例教程》考试卷B答案.docx
Java程序设计案例教程考试卷B答案()略 (二) import java.util.Scanner;public class QuestionB2 public static void main(String args) Scanner sc = new Scanner(System.in);("输入正方形的边长:");double side = sc.nextDouble();("正方形的周长:"+ 4 * side);("正方形的面积:"+ Math.pow(side, 2); ) (三)public class QuestionB3 public static void main(String args) int fl = 1, f2 = 1;for(int i = l;i <= 18;i+)System.out.print(fl + “t” + f2 + "f);if(i % 2 = 0)System.out.println();f 1 = f 1 + f2;f 2 = f2 + fl;) (四)public abstract class Vehicle private String fuel;燃料 private double speed;速度public String getFuel() return fuel;)public void setFuel(String fuel) this.fuel = fuel;)public double getSpeed() return speed;public void setSpeed(double speed) this.speed = speed;)public abstract void run();)(五)public class Automobile extends Vehicle private String brand;品牌public String getBrand() return brand;)public void setBrand(String brand) this.brand = brand;)Overridepublic void run() ("在公路上行驶");)(六)import java.util.Scanner;public class QuestionB6 public static void main(String args) Scanner sc = new Scanner(System.in);("输入杨辉三角的级数:"); int level = sc.nextlnt();int y = new intlevel川;行数 int i, j;for(i = 0;i < y.length;i+)yi = new int+ 1;歹ij数y00 = 1;第一行笫一列元素 for(i = l;i < y.length;i+)yi0 = 1;从第二行开始所有第一列所有元素 for(j = l;j< yi.length - l;j+)从第三行开始yiU = yi- 1JU-1 +冲-第一列和对角线之外元素 yiyi.length-l = 1;从第二行开始所有对角线元素)for(i = y.length - l;i >= 0;i-)输出for(j = 0;j < yi.length;j+)System.out.print(yij + "");System.out.printlnf);)(七)public class QuestionB7 extends Thread public void run() try(for(int i = l;i <= 10;i+)System.out.println(int)(Math.random() * 100);sleep(SOO);)catch(lnterruptedException ie)ie.printStackTrace();)public static void main(String args) QuestionB7 qb7 = new QuestionB7();qb7.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 QuestionB8 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);)tryConnectioncon=DriverManager.getConnection("jdbc:mysql:/localhost:3306/myShujiku", "root", "mysql");PreparedStatement ps = con.prepareStatement("select * from zhanghu where xm =?");ps.setString(l, xm);ResultSet rs = ps.executeQuery();if(rs.next()if(DigestUtils.md5Hex(password).equals(rs.getString("mm")用户密码摘要 处理("欢迎访问数据库!");else("密码不正确!");elseSystem.out.println("用户不存在!");rs.close();ps.closef);con.close();catch(SQLException ce)System.out.println(ce);