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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始


【一】小媛寄语
①不管是考试、还是自己平时做练习、敲代码。最好养成习惯,答题思路要清晰,写写注释不仅是帮助别人看懂代码,更是帮助自己以后复习都靠谱一点。
②内容放进来,代码部分的文字格式居然被网页格式化了,括号全跑左边了,有点难看。有强迫症的可以下载pdf看看


【二】习题
①抛砖引玉,解答得不是很好。坐等码神来斧正


黑马程序员训练营基础测试(第九题还没来得及做,第十题不会)



1、 请说明Collection,List,Map,Set之间的关系
Collection集合框架是整个集合最顶层的体系;该体系包括了List 和 Set集合体系;
②List属于Collection体系中的成员,是抽象类,List集合常用子子类:ArrayList and LinkedList 子类集合;List集合的底层框架数据结构是Map映射,及哈希表;
③Set属于Collection体系中的成员,是抽象类,Set集合常用子类有 :HashSet and TreeSet
④Map映射是特殊的集合,常用的Map子类包括:HashMap and TreeMap;在数据结构示图中,与Collection集合框架并列;
2、 已知一个int类型的数组,用冒泡排序法将数组中的元素进行升序排列。
[size=10.0000pt]package bubblesort;
[size=10.0000pt]/**
[size=10.0000pt] * [size=10.0000pt]@author[size=10.0000pt] [size=10.0000pt]小媛
[size=10.0000pt] * 定义功能:实现冒泡排序;
[size=10.0000pt] */
[size=10.0000pt]public [size=10.0000pt]class BubbleSort {
       
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void main(String[] args){
               
                [size=10.0000pt]int[] numSort = {1, 5, 6, 2, 8, 5};
                printArr(numSort);
                sort(numSort);
                printArr(numSort);
        }
       
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void sort([size=10.0000pt]int[] numSort){
               
                [size=10.0000pt]for([size=10.0000pt]int x = 0; x < numSort.[size=10.0000pt]length -1; x++){
                       
                        [size=10.0000pt]for([size=10.0000pt]int y = 0; y < numSort.[size=10.0000pt]length - x -1; y++){
                                       
                                [size=10.0000pt]if(numSort[y] > numSort[y+1]){
                                       
                                        [size=10.0000pt]int temp = numSort[y];
                                       
                                        numSort[y] = numSort[y + 1];
                                       
                                        numSort[y + 1] = temp;
                                }
                        }                                       
                }
        }
       
        [size=10.0000pt]/**
[size=10.0000pt]        [size=10.0000pt] * 打印传入的int[]数组
[size=10.0000pt]        [size=10.0000pt] * ①数组通过for遍历后才能打印,否则获取的是数组的地址值
[size=10.0000pt]        [size=10.0000pt] * ②注意打印的格式
[size=10.0000pt]        [size=10.0000pt] * [size=10.0000pt]@param[size=10.0000pt] arr
[size=10.0000pt]        [size=10.0000pt] */
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void printArr([size=10.0000pt]int[] arr){
               
                System.[size=10.0000pt]out.print([size=10.0000pt]"[");
                [size=10.0000pt]for ([size=10.0000pt]int i = 0; i < arr.[size=10.0000pt]length; i++) {
                       
                        [size=10.0000pt]if(i != arr.[size=10.0000pt]length -1){
                                System.[size=10.0000pt]out.print(arr + [size=10.0000pt]",");
                        }[size=10.0000pt]else{
                                System.[size=10.0000pt]out.println(arr + [size=10.0000pt]"]");                [size=10.0000pt]//打印并换行;[size=10.0000pt]        [size=10.0000pt]       
                        }
                }
        }
}




黑马测试题目.pdf

163.09 KB, 下载次数: 210

11 个回复

倒序浏览
3、 环境变量path和classpath的作用是什么?
①path环境变量是操作系统设置的路径作用于整个系统;
②classpath环境变量是Java class文件的路径;

4、 排序有哪几种方法?请列举。并用JAVA实现一个快速排序.
①常用的排序方法有:冒泡排序;选择排序,二分法排序(只适用于有序的数组),使用Java封装好的Collections.sort();或者Arrays.sort();
[size=10.0000pt]package bubblesort;
[size=10.0000pt]/**
[size=10.0000pt] * [size=10.0000pt]@author[size=10.0000pt] [size=10.0000pt]小媛
[size=10.0000pt] * 定义功能:实现冒泡排序;
[size=10.0000pt] */
[size=10.0000pt]public [size=10.0000pt]class BubbleSort {
       
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void main(String[] args){
               
                [size=10.0000pt]int[] numSort = {1, 5, 6, 2, 8, 5};
                printArr(numSort);
                sort(numSort);
                printArr(numSort);
               
        }
       
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void sort([size=10.0000pt]int[] numSort){
               
                [size=10.0000pt]for([size=10.0000pt]int x = 0; x < numSort.[size=10.0000pt]length -1; x++){
                       
                        [size=10.0000pt]for([size=10.0000pt]int y = 0; y < numSort.[size=10.0000pt]length - x -1; y++){
                                       
                                [size=10.0000pt]if(numSort[y] > numSort[y+1]){
                                       
                                        [size=10.0000pt]int temp = numSort[y];
                                       
                                        numSort[y] = numSort[y + 1];
                                       
                                        numSort[y + 1] = temp;
                                }
                        }                                       
                }
        }
       
        [size=10.0000pt]/**
[size=10.0000pt]        [size=10.0000pt] * 打印传入的int[]数组
[size=10.0000pt]        [size=10.0000pt] * ①数组通过for遍历后才能打印,否则获取的是数组的地址值
[size=10.0000pt]        [size=10.0000pt] * ②注意打印的格式
[size=10.0000pt]        [size=10.0000pt] * [size=10.0000pt]@param[size=10.0000pt] arr
[size=10.0000pt]        [size=10.0000pt] */
        [size=10.0000pt]public [size=10.0000pt]static [size=10.0000pt]void printArr([size=10.0000pt]int[] arr){
               
                System.[size=10.0000pt]out.print([size=10.0000pt]"[");
                [size=10.0000pt]for ([size=10.0000pt]int i = 0; i < arr.[size=10.0000pt]length; i++) {
                       
                        [size=10.0000pt]if(i != arr.[size=10.0000pt]length -1){
                                System.[size=10.0000pt]out.print(arr + [size=10.0000pt]",");
                        }[size=10.0000pt]else{
                                System.[size=10.0000pt]out.println(arr + [size=10.0000pt]"]");                [size=10.0000pt]//打印并换行;[size=10.0000pt]        [size=10.0000pt]       
                        }
                }
        }
}



回复 使用道具 举报
郁闷。格式被网页打乱了
回复 使用道具 举报
重新发没有格式的。
黑马程序员训练营基础测试



1、请说明Collection,List,Map,Set之间的关系
①Collection集合框架是整个集合最顶层的体系;该体系包括了List 和 Set集合体系;
②List属于Collection体系中的成员,是抽象类,List集合常用子子类:ArrayList and LinkedList 子类集合;List集合的底层框架数据结构是Map映射,及哈希表;
③Set属于Collection体系中的成员,是抽象类,Set集合常用子类有 :HashSet and TreeSet
④Map映射是特殊的集合,常用的Map子类包括:HashMap and TreeMap;在数据结构示图中,与Collection集合框架并列;
2、已知一个int类型的数组,用冒泡排序法将数组中的元素进行升序排列。
package bubblesort;
/**
* @author 小媛
* 定义功能:实现冒泡排序;
*/
public class BubbleSort {
       
        public static void main(String[] args){
               
                int[] numSort = {1, 5, 6, 2, 8, 5};
                printArr(numSort);
                sort(numSort);
                printArr(numSort);
        }
       
        public static void sort(int[] numSort){
               
                for(int x = 0; x < numSort.length -1; x++){
                       
                        for(int y = 0; y < numSort.length - x -1; y++){
                                       
                                if(numSort[y] > numSort[y+1]){
                                       
                                        int temp = numSort[y];
                                       
                                        numSort[y] = numSort[y + 1];
                                       
                                        numSort[y + 1] = temp;
                                }
                        }                                       
                }
        }
       
        /**
         * 打印传入的int[]数组
         * ①数组通过for遍历后才能打印,否则获取的是数组的地址值
         * ②注意打印的格式
         * @param arr
         */
        public static void printArr(int[] arr){
               
                System.out.print("[");
                for (int i = 0; i < arr.length; i++) {
                       
                        if(i != arr.length -1){
                                System.out.print(arr[i] + ",");
                        }else{
                                System.out.println(arr[i] + "]");                //打印并换行;               
                        }
                }
        }
}
回复 使用道具 举报

3、环境变量path和classpath的作用是什么?
①path环境变量是操作系统设置的路径作用于整个系统;
②classpath环境变量是Java class文件的路径;

4、排序有哪几种方法?请列举。并用JAVA实现一个快速排序.
①常用的排序方法有:冒泡排序;选择排序,二分法排序(只适用于有序的数组),使用Java封装好的Collections.sort();或者Arrays.sort();
②package bubblesort;
/**
* @author 小媛
* 定义功能:实现冒泡排序;
*/
public class BubbleSort {
       
        public static void main(String[] args){
               
                int[] numSort = {1, 5, 6, 2, 8, 5};
                printArr(numSort);
                sort(numSort);
                printArr(numSort);
               
        }
       
        public static void sort(int[] numSort){
               
                for(int x = 0; x < numSort.length -1; x++){
                       
                        for(int y = 0; y < numSort.length - x -1; y++){
                                       
                                if(numSort[y] > numSort[y+1]){
                                       
                                        int temp = numSort[y];
                                       
                                        numSort[y] = numSort[y + 1];
                                       
                                        numSort[y + 1] = temp;
                                }
                        }                                       
                }
        }
       
        /**
         * 打印传入的int[]数组
         * ①数组通过for遍历后才能打印,否则获取的是数组的地址值
         * ②注意打印的格式
         * @param arr
         */
        public static void printArr(int[] arr){
               
                System.out.print("[");
                for (int i = 0; i < arr.length; i++) {
                       
                        if(i != arr.length -1){
                                System.out.print(arr[i] + ",");
                        }else{
                                System.out.println(arr[i] + "]");                //打印并换行;               
                        }
                }
        }
}
回复 使用道具 举报

5、定义一个学生类, 需要有姓名, 年龄, 考试成绩三个成员属性. 属性(成员变量)需要私有并提供get, set方法, 可以通过构造函数进行初始化.
package student;

/**
* @author 小媛
* Student class
* ① properties:name and age
* ②constructor , set() get() method
*/
public class Student {

        private String name;
        private int age;
       
        Student(String name, int age){
               
                this.name = name;
                this.age = age;
        }
        public void setName(String name){
               
                this.name = name;
        }
        public String getName(){
               
                return name;
        }
        public void setAge(int age){
               
                this.age = age;
        }
        public int getAge(){
               
                return age;
        }
}

6、编写一个类Person,为Person类定义年龄、姓名两个属性,并且定义一个SayHello方法,方法执行时输出“我是***我的年龄是***”;定义一个Chinese类从Person类继承。
package person;

/**
* @author 小媛
*        Person class:
* ①age;name;
* ②sayHello method;
*         Chinese class extends Person class;
*/
class Person {
       
        private String name;
        private int age;
       
        Person(String name, int age){
               
                this.name = name;
                this.age = age;
        }
        public void setName(String name){
               
                this.name = name;
        }
        public String getName(){
               
                return name;
        }
        public void setAge(int age){
               
                this.age = age;
        }
        public int getAge(){
               
                return age;
        }

        public void sayHello(){       
                System.out.println("我是" + this.name + "我的年龄是:" + this.age );
        }
}

package person;

public class Chinese extends Person{
       
        Chinese(String name, int age){       
                super(name, age);
        }
}
回复 使用道具 举报
7、先写一个程序,打印从1到100的值。之后修改程序,通过使用break关键词,使得程序在打印到98时退出。然后尝试使用return来达到相同的目的。
package Printnumber;

/**
* @author 小媛
* PrintHundred class
* ① for sentence to get 1 - 100
* ②if variable = 98, then break
*/
public class Printonttohundred {

        public static void main(String [] args){
               
                int result = printNum2();
                System.out.println(result);
        }
       
        public static void printNum(){
               
                for(int x = 1; x <= 100; x++){
                                       
                                        if( x == 98){
                                                break;
                                        }
                                       
                                System.out.println("x :" + x);
                                       
                }
        }
       
        public static int printNum2(){
               
                int a = 0;
               
                for(int x = 1; x <= 100; x++){       
                       
                        a= x;
                        System.out.println(a);
                       
                        if( x==98){       
                                return -2;
                        }
                }
               
                return -1;
        }
}
       
8、 用控制台程序输出九九乘法表;输出结果按下图所示:
      1*1=1
      1*2=2   2*2=4
      1*3=3   2*3=6   3*3=9
       .........
package multiplysheet;
/**
* @author 小媛
*        double for sentence to get 99multiply sheet
*/
public class MultiplySheet {
       
        public static void main(String[] args){
               
                multiplySheet();
               
        }
       
        public static void multiplySheet(){
               
                for(int x = 0; x <= 9; x++){
                       
                        for(int y = 0;y <= x; y++){
                               
                                System.out.print( x + "*" + y + "=" + x*y +"\t");
                        }
                        System.out.println();
                }
        }
}
回复 使用道具 举报
我把自己答题的word改成pdf 上传了。
大家要是看着上面的太乱,就在直接看pdf吧。唉,把自己写的word文档复制粘贴放到黑马论坛都搞不好····我在怀疑我的计算机能力啊
(╯‵□′)╯︵┻━┻      /(ㄒoㄒ)/~~

黑马测试题目.pdf

163.09 KB, 下载次数: 164

回复 使用道具 举报
怎么感觉你的题都好简单啊。。
回复 使用道具 举报
一枚小小媛 发表于 2015-7-26 12:02
5、定义一个学生类, 需要有姓名, 年龄, 考试成绩三个成员属性. 属性(成员变量)需要私有并提供get, set方法 ...

哪里找的测试题目??
回复 使用道具 举报
这是其中一题吗?
回复 使用道具 举报
楼主费心了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马