A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© careit 中级黑马   /  2014-8-27 07:55  /  1958 人查看  /  28 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

黑马程序员训练营基础测试
1、 从键盘接受一个数字,打印该数字表示的时间,最大单位到天,例如:
键盘输入6,打印6秒;
键盘输入60,打印1分;
键盘输入66,打印1分6秒;
键盘输入666,打印11分6秒;
键盘输入3601,打印1小时1秒
2、 定义一个二维int数组,编写代码获取最小元素。
3、 Collection和Collections有什么关系?List和Set有什么异同点?Map有哪些常用类,各有什么特点?
4、 编写一个函数,函数内输出一个字符串,并在主函数内调用它。
5、 编写一个延迟加载的单例设计模式。
6、 编写程序,打印1到100之内的整数,但数字中包含7的要跳过,例如:17、27、71、72
7、 throw和throws有什么区别? try、catch、finally分别在什么情况下使用?
8、 声明类Student,包含3个成员变量:name、age、score,要求可以通过 new Student("张三", 22, 95) 的方式创建对象,并可以通过set和get方法访问成员变量
9、 求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000
10、声明类Student,包含3个成员变量:name、age、score,创建5个对象装入TreeSet,按照成绩排序输出结果(考虑成绩相同的问题)。

第  1  、6、7、9、10题可以把玩把玩,各位看看,一会上我做的

评分

参与人数 3技术分 +4 黑马币 +2 收起 理由
卢仪敏 + 3 很给力!
追求卓越 + 1 赞一个!
天黑偷牛 + 2 赞一个!

查看全部评分

28 个回复

正序浏览
谢谢分享  可以看看
回复 使用道具 举报
楼主很赞
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
感谢分享
回复 使用道具 举报
谢谢楼主分享
回复 使用道具 举报
楼主解答的很好啊
回复 使用道具 举报
感谢楼主分享,只有2个与我一样
回复 使用道具 举报
能看书做么?
回复 使用道具 举报
好的 有些题 跟我一样
回复 使用道具 举报

谢谢lz的分享
.{:3_46:}
回复 使用道具 举报
我感觉很难啊  打击很大呀 唉
回复 使用道具 举报
dhgcy 中级黑马 2014-8-28 08:49:38
17#
谢谢分享    值得一看
回复 使用道具 举报
学习一下
回复 使用道具 举报
牛人啊!!!!
回复 使用道具 举报
谢谢分享,连答案的都有。
回复 使用道具 举报
第九题
  1. package com.itheima;

  2. import java.math.BigInteger;

  3. public class Test9 {

  4.         /**
  5.          * @param args
  6.          * 第9题:求1000!的结果中包含多少个0?注:1000! = 1×2×3×4×5×...×999×1000
  7.          */
  8.         public static void main(String[] args) {
  9.                 // TODO Auto-generated method stub
  10.                 //
  11.                 int end=1000;
  12.         BigInteger res = new BigInteger("1");
  13.         //显然1000!的结果将超出int的表达范围,所以使用java包含的BigInteger来进行运算
  14.         //该类封装了字符串形式的算术运算
  15.         for(int i=1;i<=end;i++) {
  16.             res = res.multiply(new BigInteger(i+""));//乘
  17.         }
  18.         String string=res.toString();
  19.         int count=0;
  20.         //统计结果中包含多少个  0
  21.         for (int i = 0; i < string.length(); i++) {
  22.             if(string.charAt(i)=='0')
  23.                     count++;
  24.         }
  25.         System.out.println("结果中共有"+count+"个0");
  26.         }
  27.        

  28. }
复制代码

6000!的结果超出了表示范围,BigInteger提供了对大整数进行算术运算的方法,;
后来在网下看这个题,有一个类似的,计算末尾有多少连续0;
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
第十题
  1. package com.itheima;

  2. import java.util.Comparator;
  3. import java.util.Iterator;
  4. import java.util.TreeSet;

  5. public class Test10 {

  6.         /**
  7.          * @param args
  8.          * 10、声明类Student,包含3个成员变量:name、age、score,
  9.          * 创建5个对象装入TreeSet,按照成绩排序输出结果(考虑成绩相同的问题)
  10.          */
  11.         public static void main(String[] args) {
  12.                 // TODO Auto-generated method stub
  13.                 TreeSet<Student> treeSet=new TreeSet();
  14.                 //实例化5个student对象
  15.                 Student[] stuArr={new Student("赵", 20, 97),
  16.                                            new Student("钱", 22, 84),
  17.                                            new Student("孙", 21, 97),
  18.                                            new Student("李", 23, 89),
  19.                                            new Student("崔", 19, 99)};
  20.                 //将5个student对象增加到TreeSet对象中
  21.                 treeSet.add(stuArr[0]);
  22.                 treeSet.add(stuArr[1]);
  23.                 treeSet.add(stuArr[2]);
  24.                 treeSet.add(stuArr[3]);
  25.                 treeSet.add(stuArr[4]);
  26.                 Iterator it=treeSet.iterator();
  27.                 //获取treeSet的遍历器
  28.                 while(it.hasNext()){
  29.                         Student p = (Student)it.next();
  30.                           System.out.println("name = "+p.getName()+" || age = "+p.getAge()+" || age = "+p.getScore());
  31.                           }
  32.         }
  33.         static class Student implements Comparable{
  34.                 //实现Comparable 接口的compareTo(Object o)方法
  35.                 private String name;
  36.                 private int age;
  37.                 private float score;
  38.                 public Student(String n,int a,float s) {
  39.                         // TODO Auto-generated constructor stub
  40.                         name=n;
  41.                         age=a;
  42.                         score=s;
  43.                 }
  44.                 public String getName() {
  45.                         return name;
  46.                 }
  47.                 public void setName(String name) {
  48.                         this.name = name;
  49.                 }
  50.                 public int getAge() {
  51.                         return age;
  52.                 }
  53.                 public void setAge(int age) {
  54.                         this.age = age;
  55.                 }
  56.                 public float getScore() {
  57.                         return score;
  58.                 }
  59.                 public void setScore(float score) {
  60.                         this.score = score;
  61.                 }
  62.                 @Override
  63.                 public int compareTo(Object o) {
  64.                         // TODO Auto-generated method stub
  65.                         Student stu=(Student) o;
  66.                         //以下实现的是升序排列
  67.                         if(this.score>stu.score){
  68.                                 return 1;
  69.                         }
  70.                         if(this.score<stu.score){
  71.                                 return -1;
  72.                         }
  73.                         return 0;
  74.                 }
  75.         }
  76. }
复制代码

为啥我是10个题
回复 使用道具 举报
谢谢楼主分享
回复 使用道具 举报
careit 中级黑马 2014-8-27 11:21:33
9#
第7题 :
  1. package com.itheima;

  2. public class Test7 {

  3.         /**
  4.          * @param args
  5.          * 第7题:throw和throws有什么区别? try、catch、finally分别在什么情况下使用?
  6.          */
  7.         /*
  8.          * 用try ,catch“捕获”(不管有没有实际捕获住)
  9.          * 处理方式有两种,        1:该方法处理,在catch中自己处理该异常
  10.          *                                         2:该方法不管,而是抛出,由调用该方法的方法捕获处理
  11.          * 方法内部用throw,方法外部用 有了throws,
  12.          * 有throw,就有throws
  13.          * throw在内,throws在外
  14.          * 对于有抛出异常的方法必须使用try-catch 捕获
  15.          *
  16.          * 而finally不管有没有异常一定会执行的语句。
  17.          *
  18.          * 请看如下例子
  19.          *
  20.          * 以测试将字符串“12” 和 “12a”  转化为int型数据为例,
  21.          * test  12  将不会出现异常
  22.          * test  12a 将会出现异常,该测试用例都使用try-catch-finally 用于确定finally的
  23.          * 执行情况
  24.          * */
  25.         public static void main(String[] args) {
  26.                 // TODO Auto-generated method stub
  27.                 System.out.println("-------------test 12-----------------");
  28.                 try {
  29.                         testThrowsException("12");
  30.                 } catch (Exception e) {
  31.                         // TODO: handle exception
  32.                         System.out.println(e.toString());
  33.                 }finally {
  34.                         System.out.println("finally 1");
  35.                 }
  36.                 System.out.println("-------------test 12a-----------------");
  37.                 try {
  38.                         testThrowsException("12a");
  39.                 } catch (Exception e) {
  40.                         // TODO: handle exception
  41.                         System.out.println(e.toString());
  42.                 }finally {
  43.                         System.out.println("finally 2");
  44.                 }
  45.                 System.out.println();
  46.         }
  47.         static void testThrowsException(String s) throws Exception{
  48.                 //testThrowsException 将捕获的异常抛出
  49.                 try {
  50.                         int i=Integer.parseInt(s);
  51.                 } catch (Exception e) {
  52.                         // TODO: handle exception
  53.                         throw new Exception("eeeeee"+e.getMessage());
  54.                 }finally {
  55.                         System.out.println("finally3");
  56.                 }
  57.         }
  58. }
复制代码


光说不行,得体现出来


第八题:
不说了
  1. package com.itheima;

  2. public class Test8 {

  3.         /**
  4.          * 声明类StudenStudentt,包含3个成员变量:name、age、score,
  5.          * 要求可以通过 new Student("张三", 22, 95) 的方式创建对象,
  6.          * 并可以通过set和get方法访问成员变量
  7.          * @param args
  8.          */
  9.         public static void main(String[] args) {
  10.                 // TODO Auto-generated method stub
  11.                 Student student=new Student("张三", 22, 95.0f);
  12.                 System.out.println("名字"+student.getName());
  13.                 System.out.println("年龄"+student.getAge());
  14.                 student.setAge(23);
  15.                 System.out.println("年龄"+student.getAge());
  16.         }
  17.         static class Student{
  18.                 private String name;
  19.                 private int age;
  20.                 private float score;
  21.                 //构造方法,需要三个参数
  22.                 public Student(String n,int a,float s) {
  23.                         // TODO Auto-generated constructor stub
  24.                         name=n;
  25.                         age=a;
  26.                         score=s;
  27.                 }
  28.                 //使用Eclipse 快速工具生成以下get  set方法
  29.                 public String getName() {
  30.                         return name;
  31.                 }
  32.                 public void setName(String name) {
  33.                         this.name = name;
  34.                 }
  35.                 public int getAge() {
  36.                         return age;
  37.                 }
  38.                 public void setAge(int age) {
  39.                         this.age = age;
  40.                 }
  41.                 public float getScore() {
  42.                         return score;
  43.                 }
  44.                 public void setScore(float score) {
  45.                         this.score = score;
  46.                 }
  47.         }
  48. }
复制代码
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马