編程題包括sql

一、單例模式
餓漢模式
public class Singleton {
    private Singleton(){};

    private static Singleton Instance = new Singleton();

    public static Singleton getInstance(){
        return Instance;
}
懶漢模式
public class Singleton {
    private Singleton(){}
    private static class LazyHodler{
        private static Singleton Instance = new Singleton();
    }
    public static Singleton getInstance(){
        return LazyHodler.Instance;
    }
}
二、數組操作
/**
* 1.獲取數組中的最大值/最小值
*/
public static int getMax(int[] arr) {
        int max = arr[0];
        for (int x = 1; x < arr.length; x++) {
            if (arr[x] > max)
                max = arr[x];
        }
        return max;
}
/**
 * 2.給數組排序,選擇排序和冒泡排序
 */
public static void selectSort(int[] arr) {
    for (int x = 0; x < arr.length - 1; x++) {
        for (int y = x + 1; y < arr.length; y++) {
            if (arr[x] > arr[y]) {
                swap(arr, x, y);
            }
        }
    }
}
public static void swap(int[] arr, int a, int b) {
    int temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;
}
public static void bubbleSort(int[] arr) {
    for (int x = 0; x < arr.length - 1; x++) {
        for (int y = 0; y < arr.length - x - 1; y++)//-x:讓每一次比較的元素減少,-1:避免角標越界。
        {
            if (arr[y] < arr[y + 1]) {
                swap(arr, y, y + 1);
            }
        }
    }
}

/**
 * 3.對給定的數組進行反轉
 */
public static void reverseArray(int[] arr) {
    for (int start = 0, end = arr.length - 1; start < end; start++, end--) {
        swap(arr, start, end);
    }
}
/**
 * 4.數組的查找操作,
 */
public static int getIndex(int[] arr, int key) {
    for (int x = 0; x < arr.length; x++) {
        if (arr[x] == key)
            return x;
    }
    return -1;
}
//二分法查找,先排序
public static int halfSearch(int[] arr, int key) {
    int min, max, mid;
    min = 0;
    max = arr.length - 1;
    mid = (max + min) / 2;

    while (arr[mid] != key) {
        if (key > arr[mid])
            min = mid + 1;
        else if (key < arr[mid])
            max = mid - 1;

        if (min > max)
            return -1;
        mid = (max + min) / 2;
    }
    return mid;
}
//保留小數點,在四舍五入后
public class TestMath {
    public static void main(String[] args) {
        /*
        Random r = new Random();
        for(int x=0; x<10; x++)
        {
            //int d = (int)(Math.random()*10+1);
            int d = r.nextInt(10)+1;
            sop(d);
        }
        */
        saveTwo(12.3456, 2, true);//12.34
    }

    public static void saveTwo(double d, int scale, boolean isRound) {

        double base = Math.pow(10, scale);
        double num = isRound ? Math.round(d * base) / base : ((int) (d * base)) / base;
        sop("num=" + num);
        /*
        double d1 = d*100;
        sop("d1="+d1);
        d1 = d1+0.5;
        double d2 = (int)d1;
        sop("d2="+d2);
        double d3 = d2/100;
        sop("d3="+d3);
        */
    }
    public static void show() {
        double d = Math.ceil(16.34);//ceil返回大于指定數據的最小整數。
        double d1 = Math.floor(12.34);//floor返回小于指定數據的最大整數。
        long l = Math.round(12.54);//四舍五入
        sop("d=" + d);
        sop("d1=" + d1);
        sop("l=" + l);
        double d2 = Math.pow(2, 3);
        sop("d2=" + d2);
    }
    public static void sop(Object obj) {
        System.out.println(obj);
    }
}
三、字符串操作
/*基本數據類型對象包裝類。
byte    Byte
short   short
int     Integer
long    Long
boolean Boolean
float   Float
double  Double
char    Character
基本數據類型轉成字符串。
    基本數據類型+""
    包裝類.toString(基本數據類型值);
    如: Integer.toString(34);//將34整數變成"34";
字符串轉成基本數據類型。
    xxx a = Xxx.parseXxx(String);
    int a = Integer.parseInt("123");
    double b = Double.parseDouble("12.23");
    boolean b = Boolean.parseBoolean("true");
    Integer i = new Integer("123");
    int num = i.intValue();
/**
 * 將字符串變成數組
 * 對數組反轉,將數組變成字符串
 */
public static String reverseString(String s, int start, int end) {
    //字符串變數組。
    char[] chs = s.toCharArray();
    //反轉數組。
    reverse(chs, start, end);
    //將數組變成字符串。
    return new String(chs);
}

private static void reverse(char[] arr, int x, int y) {
    for (int start = x, end = y - 1; start < end; start++, end--) {
        swap(arr, start, end);
    }
}

private static void swap(char[] arr, int x, int y) {
    char temp = arr[x];
    arr[x] = arr[y];
    arr[y] = temp;
}
/**
 * 去除字符串兩端空格
 */
public static String myTrim(String str) {
    int start = 0, end = str.length() - 1;
    while (start <= end && str.charAt(start) == ' ')
        start++;
    while (start <= end && str.charAt(end) == ' ')
        end--;
    return str.substring(start, end + 1);
}
/**
 * 子串在整串中出現的次數。
 */
private static int getCount(String str, String ref) {
    int count = 0;
    while (str.contains(ref)) {
        str = str.substring(str.indexOf(ref) + ref.length());
        count++;
    }
    return count;
}
/**
 * 對字符串中字符進行自然順序排序。
 * 思路:字符串變成字符數組,對數組排序,選擇,冒泡,Arrays.sort(),將排序后的數組變成字符串。
 */
/**
 * 要求對字符串中的數值進行排序。生成一個數值從小到大新字符串。
 * 思路:
 * 1,將字符串切割。變成字符串數組。
 * 2,將字符串數組轉成int數組。
 * 3,int數組排序。
 * 4,將int數組變成字符串。
 */
public static String numberStringSort(String str) {
    String[] arr = splitString(str);
    int[] nums = toIntArray(arr);
    Arrays.sort(nums);
    return intArraytoString(nums);
}
private static String[] splitString(String str) {
    return str.split(" ");
}
private static int[] toIntArray(String[] arr) {
    int[] nums = new int[arr.length];

    for (int x = 0; x < arr.length; x++) {
        nums[x] = Integer.parseInt(arr[x]);
    }
    return nums;
}
private static String intArraytoString(int[] arr) {
    StringBuilder sb = new StringBuilder();

    for (int x = 0; x < arr.length; x++) {
        if (x != arr.length - 1)
            sb.append(arr[x] + " ");
        else
            sb.append(arr[x]);
    }
    return sb.toString();
}
/**
 * 獲取兩個字符串中最大相同子串。第一個動作:將短的那個串進行長度一次遞減的子串打印
 * "abcwerthelloyuiodef"  "cvhellobnm"
 * 思路:將短的那個子串按照長度遞減的方式獲取到,將每獲取到的子串去長串中判斷是否包含,如果包含,已經找到!
 */
public static String getMaxSubString(String s1, String s2) {

    String max = "", min = "";

    max = (s1.length() > s2.length()) ? s1 : s2;

    min = (max == s1) ? s2 : s1;

    for (int x = 0; x < min.length(); x++) {
        for (int y = 0, z = min.length() - x; z != min.length() + 1; y++, z++) {
            String temp = min.substring(y, z);
            //sop(temp);
            if (max.contains(temp))//if(s1.indexOf(temp)!=-1)
                return temp;
        }
    }
    return "";
}
四、集合操作
/*Collection定義了集合框架的共性功能。
        1,添加
        add(e);
        addAll(collection);

        2,刪除
        remove(e);
        removeAll(collection);
        clear();

        3,判斷。
        contains(e);
        isEmpty();

        4,獲取
        iterator();
        size();

        5,獲取交集。
        retainAll();

        6,集合變數組。
        toArray();

        1,add方法的參數類型是Object。以便于接收任意類型對象。

        2,集合中存儲的都是對象的引用(地址)


        什么是迭代器呢?
        其實就是集合的取出元素的方式。
        如同抓娃娃游戲機中的夾子。

        迭代器是取出方式,會直接訪問集合中的元素。
        所以將迭代器通過內部類的形式來進行描述。
        通過容器的iterator()方法獲取該內部類的對象。
*/
  • List
/**
 * Created by joshul on 2017/3/6.
 * ArrayList 數組形式訪問List鏈式集合數據,元素可重復,訪問元素較快  數組
 * LinkedList 鏈表方式的List鏈式集合,元素可重復,元素的插入刪除較快 雙向鏈表
 */
public class TestList {
    public static void main(String[] args) {

    }

    /**
     * ArrayList 數組形式訪問List鏈式集合數據,元素可重復,訪問元素較快  數組
     * @param al
     * @return
     */
    public static ArrayList singleElement(ArrayList al) {
        //定義一個臨時容器。
        ArrayList newAl = new ArrayList();
        Iterator it = al.iterator();
        while(it.hasNext())
        {
            Object obj = it.next();
            if(!newAl.contains(obj))
                newAl.add(obj);
        }
        return newAl;
    }
}
  • Set
/**
 * Created by joshul on 2017/3/6.
 * Set的核心概念就是集合內所有元素不重復。在Set這個子接口中沒有在Collection特別實現什么額外的方法,應該只是定義了一個Set概念。
 * 下面我們來看Set的幾個常用的實現HashSet、LinkedHashSet、TreeSet
 * <p>
 * HashSet  無序的、無重復的數據集合    基于HashMap
 * LinkedSet    維護次序的HashSet    基于LinkedHashMap
 * TreeSet  保持元素大小次序的集合,元素需要實現Comparable接口  基于TreeMap
 */
public class TestSet {

    /**
     * "90 -7 0 18 2 45 4",將字符串中的數值進行排序。使用TreeSet完成。
     * 將字符串切割,可以將這些對象存入TreeSet集合。因為TreeSet自身具備排序功能。
     */
    public static void main(String[] args) {
        String str = "90 -7 0 18 2 45 4";
        String[] arr = str.split(" ");
        TreeSet ts = new TreeSet();
        for (int x = 0; x < arr.length; x++) {
            //ts.add(new Integer(arr[x]));
            ts.add(Integer.parseInt(arr[x]));//
        }
        System.out.println(ts);
    }
}
  • Mep
public class TestMap {
    public static void main(String[] args) {
        String s= charCount("ak+abAf1c,dCkaAbc-defa");
        System.out.println(s);
    }

    /**
     * "sdfgzxcvasdfxcvdf"獲取該字符串中的字母出現的次數。
     * 希望打印結果:a(1)c(2).....
     * 思路:
     * 1,將字符串轉換成字符數組。因為要對每一個字母進行操作。
     * 2,定義一個map集合,因為打印結果的字母有順序,所以使用treemap集合
     * 3,遍歷字符數組。
     * 將每一個字母作為鍵去查map集合。
     * 如果返回null,將該字母和1存入到map集合中。
     * 如果返回不是null,說明該字母在map集合已經存在并有對應次數。那么就獲取該次數并進行自增。,然后將該字母和自增后的次數存入到map集合中。覆蓋調用原理鍵所對應的值。
     * 4,將map集合中的數據變成指定的字符串形式返回。
     */
    public static String charCount(String str) {
        char[] chs = str.toCharArray();

        TreeMap<Character, Integer> tm = new TreeMap<Character, Integer>();
        int count = 0;
        for (int x = 0; x < chs.length; x++) {
            if (!(chs[x] >= 'a' && chs[x] <= 'z' || chs[x] >= 'A' && chs[x] <= 'Z'))
                continue;
            Integer value = tm.get(chs[x]);
            if (value != null)
                count = value;
            count++;
            tm.put(chs[x], count);//直接往集合中存儲字符和數字,為什么可以,因為自動裝箱。
            count = 0;
        }
        //System.out.println(tm);
        StringBuilder sb = new StringBuilder();
        Set<Map.Entry<Character, Integer>> entrySet = tm.entrySet();
        Iterator<Map.Entry<Character, Integer>> it = entrySet.iterator();

        while (it.hasNext()) {
            Map.Entry<Character, Integer> me = it.next();
            Character ch = me.getKey();
            Integer value = me.getValue();
            sb.append(ch + "(" + value + ")");
        }
        return sb.toString();
    }
}
四、IO操作
/**
 * Created by joshul on 2017/3/1.
 * IO流用來處理設備之間的數據傳輸
 * Java對數據的操作是通過流的方式
 * Java用于操作流的對象都在IO包中
 * 流按操作數據分為兩種:字節流與字符流
 * 流按流向分為:輸入流,輸出流。
 * 字節流的抽象基類: InputStream ,OutputStream。
 * 字符流的抽象基類: Reader , Writer。
 * InputStream的子類FileInputStream。
 * Reader的子類FileReader。
 * IO程序的書寫:
 * 導入IO包中的類
 * 進行IO異常處理
 * 在finally中對流進行關閉
 * <p>
 * 字符流的緩沖區
 * 緩沖區的出現提高了對數據的讀寫效率。
 * 對應類: BufferedWriter, BufferedReader
 * 緩沖區要結合流才可以使用,在流的基礎上對流的功能進行了增強。
 * <p>
 * 裝飾設計模式:對原有類進行了功能的改變,增強。
 */
public class Io {
    public static void main(String[] args) {
        getTime();
    }

    /**
     * 獲取現在時間
     */
    public static void getTime() {
        Date d = new Date();
        System.out.println(d);//打印的時間看不懂,希望有些格式。
        //將模式封裝到SimpleDateformat對象中。
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日E hh:mm:ss");
        //調用format方法讓模式格式化指定Date對象。
        String time = sdf.format(d);
        System.out.println("time=" + time);
        long l = System.currentTimeMillis();
        Date d1 = new Date(l);
        System.out.println("d1:" + d1);
    }

    /**
     * 讀取一個.java文件,并打印在控制臺上。
     */
    public static void readJava() {
        FileReader fr = null;
        try {
            fr = new FileReader("DateDemo.java");
            char[] buf = new char[1024];
            int num = 0;
            while ((num = fr.read(buf)) != -1) {
                System.out.print(new String(buf, 0, num));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 演示對已有文件的數據續寫。
     */
    public static void readFile() {
        FileWriter fw = null;
        try {
            //傳遞一個true參數,代表不覆蓋已有的文件。并在已有文件的末尾處進行數據續寫。
            fw = new FileWriter("demo.txt", true);
            fw.write("nihao\r\nxiexie");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * FileWriter
     */
    public static void fileWriter() {
        FileWriter fw = null;
        try {
            //創建一個FileWriter對象。該對象一被初始化就必須要明確被操作的文件。
            //而且該文件會被創建到指定目錄下。如果該目錄下已有同名文件,將被覆蓋。
            //其實該步就是在明確數據要存放的目的地。
            fw = new FileWriter("demo.txt");
            //調用write方法,將字符串寫入到流中。
            fw.write("abcde");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //刷新流對象中的緩沖中的數據。
                //將數據刷到目的地中。
                //fw.flush();
                //關閉流資源,但是關閉之前會刷新一次內部的緩沖中的數據。
                //將數據刷到目的地中。
                //和flush區別:flush刷新后,流可以繼續使用,close刷新后,會將流關閉。
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        /*//傳遞一個true參數,代表不覆蓋已有的文件。并在已有文件的末尾處進行數據續寫。
        FileWriter fw = new FileWriter("demo.txt",true);

        fw.write("nihao\r\nxiexie");

        fw.close();*/
    }
}
**
 * Created by joshul on 2017/3/6.
 * 字符流:FileReader FileWriter。/BufferedReader BufferedWriter
 * 字節流:InputStream  OutputStream
 * 需求,想要操作圖片數據。這時就要用到字節流。
 */
public class TestBuffer {
    public static void main(String[] args){

    }
    public static void BufferedReader() {
        FileReader fr = null;
        BufferedReader bufr = null;
        try {
            //創建一個讀取流對象和文件相關聯。
            fr = new FileReader("buf.txt");
            //為了提高效率。加入緩沖技術。將字符讀取流對象作為參數傳遞給緩沖對象的構造函數。
            bufr = new BufferedReader(fr);
            String line = null;
            while ((line = bufr.readLine()) != null) {
                System.out.print(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bufr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    /*public static void BufferedWriter() {
        //創建一個字符寫入流對象。
        FileWriter fw = new FileWriter("buf.txt");
        //為了提高字符寫入流效率。加入了緩沖技術。
        //只要將需要被提高效率的流對象作為參數傳遞給緩沖區的構造函數即可。
        BufferedWriter bufw = new BufferedWriter(fw);
        for(int x=1; x<5; x++)
        {
            bufw.write("abcd"+x);
            bufw.newLine();
            bufw.flush();
        }
        //記住,只要用到緩沖區,就要記得刷新。
        //bufw.flush();
        //其實關閉緩沖區,就是在關閉緩沖區中的流對象。
        bufw.close();
    }*/
}
四、SQL題
1.寫一個sql將表TEST_A(ID,NAME,CODE)中重復次數大于2的NAME值打印出來

select NAME from TEST_A
where NAME in(select NAME from TEST_A group by NAME having count(NAME)>2);

2.用一條SQL 語句 查詢出每門課都大于80 分的學生姓名student_tb

name kecheng fenshu
張三 語文 81
張三 數學 75

select name from student_tb where fenshu in(select fenshu from student_tb group by having min(fenshu)>80);

3.學生表 如下:student_tb

自動編號 學號 姓名 課程編號 課程名稱 分數
1 2005001 張三 0001 數學 69
2 2005002 李四 0001 數學 89
3 2005001 張三 0001 數學 69
刪除除了自動編號不同, 其他都相同的學生冗余信息

delete from student_tb where 自動編號 not in(select min(自動編號) from student_tb group by 學號,姓名,課程編號,課程名稱,分數)

4.一個叫 team 的表,里面只有一個字段name, 一共有4 條紀錄,分別是a,b,c,d, 對應四個球隊,現在四個球隊進行比賽,用一條sql 語句顯示所有可能的比賽組合.

select a.name,b.name from student2 a, student2 b
where a.name<b.name;

5.請用SQL 語句實現:從TestDB 數據表中查詢出所有月份的發生額都比101 科目相應月份的發生額高的科目.請注意:TestDB 中有很多科目,都有1 -12 月份的發生額.

AccID :科目代碼,Occmonth :發生額月份,DebitOccur :發生額.
數據庫名:JcyAudit,數據集:Select * from TestDB

select a.* from TestDB as a,(select Occmonth,max(DebitOccur) Debit101ccur from TestDB where AccID= '101' group by Occmonth) b
where a.Occmonth = b.Occmonth and a.DebitOccur > b.Debit101ccur

6. 面試題:怎么把這樣一個表兒

year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成這樣一個結果
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4

select year,(select amount from table_aa m where month = 1 and table_aa.year = m.year) as m1,() as m2,() as m3 from table_aa
group by year;

7. 說明:復制表( 只復制結構, 源表名:a 新表名:b)

select * into b from a where 1<>1 (where1=1,拷貝表結構和數據內容)

7. 說明:拷貝表( 拷貝數據, 源表名:a 目標表名:b)

insert into b(a, b, c) select d,e,f from a;

8. 說明:顯示文章.提交人和最后回復時間

select a.title a.name b.adddate from table a ,(select max(adddate) adddate from table where a.title = table.title) b

9. 說明:外連接查詢( 表名1 :a 表名2 :b)

select a.a,a.b,a.c,b.c,b.d,b.f from a left outer join b on a.a = b.c

10. 說明:日程安排提前五分鐘提醒

select * from 日程安排 where datediff('minute',f 開始時間,getdate())>5

11. 說明:兩張關聯表,刪除主表中已經在副表中沒有的信息

Delete from info where not exists (select * from infobz where info.infid=infobz.infid )

12. 有兩個表A 和B ,均有key 和value 兩個字段,如果B 的key 在A 中也有,就把B 的value 換為A 中對應的value

這道題的SQL 語句怎么寫?
update b set b.value=(select a.value from a where a.key=b.key) where b.id in(select b.id from b,a where b.key=a.key);

SQL面試題
1 觸發器的作用?

答:觸發器是一中特殊的存儲過程,主要是通過事件來觸發而被執行的。它可以強化約束,來維護數據的完整性和一致性,可以跟蹤數據庫內的操作從而不允許未經許可的更新和變化。
可以聯級運算。如,某表上的觸發器上包含對另一個表的數據操作,而該操作又會導致該表觸發器被觸發。

2 什么是存儲過程?用什么來調用?

答:存儲過程是一個預編譯的 SQL 語句,優點是允許模塊化的設計,就是說只需創建一次,以后在該程序中就可以調用多次。如果某次操作需要執行多次 SQL ,
使用存儲過程比單純 SQL 語句執行要快。可以用一個命令對象來調用存儲過程。

3 索引的作用?和它的優點缺點是什么?

答:索引就一種特殊的查詢表,數據庫的搜索引擎可以利用它加速對數據的檢索。它很類似與現實生活中書的目錄,不需要查詢整本書內容就可以找到想要的數據。索引可以是唯一的,
創建索引允許指定單個列或者是多個列。缺點是它減慢了數據錄入的速度,同時也增加了數據庫的尺寸大小。

3 什么是內存泄漏?

答:一般我們所說的內存泄漏指的是堆內存的泄漏。堆內存是程序從堆中為其分配的,大小任意的,使用完后要顯示釋放內存。當應用程序用關鍵字 new 等創建對象時,就從堆中為它分配一塊內存,
使用完后程序調用 free 或者 delete 釋放該內存,否則就說該內存就不能被使用,我們就說該內存被泄漏了。

4 維護數據庫的完整性和一致性,你喜歡用觸發器還是自寫業務邏輯?為什么?

答:我是這樣做的,盡可能使用約束,如 check, 主鍵,外鍵,非空字段等來約束,這樣做效率最高,也最方便。其次是使用觸發器,這種方法可以保證,
無論什么業務系統訪問數據庫都可以保證數據的完整新和一致性。最后考慮的是自寫業務邏輯,但這樣做麻煩,編程復雜,效率低下。

5 什么是事務?什么是鎖?

答:事務就是被綁定在一起作為一個邏輯工作單元的 SQL 語句分組,如果任何一個語句操作失敗那么整個操作就被失敗,以后操作就會回滾到操作前狀態,或者是上有個節點。
為了確保要么執行,要么不執行,就可以使用事務。要將有組語句作為事務考慮,就需要通過 ACID 測試,即原子性,一致性,隔離性和持久性。
鎖:在所以的 DBMS 中,鎖是實現事務的關鍵,鎖可以保證事務的完整性和并發性。與現實生活中鎖一樣,它可以使某些數據的擁有者,在某段時間內不能使用某些數據或數據結構。當然鎖還分級別的。

6 什么叫視圖?游標是什么?

答:視圖是一種虛擬的表,具有和物理表相同的功能。可以對視圖進行增,改,查,操作,試圖通常是有一個表或者多個表的行或列的子集。對視圖的修改不影響基本表。它使得我們獲取數據更容易,相比多表查詢。
游標:是對查詢出來的結果集作為一個單元來有效的處理。游標可以定在該單元中的特定行,從結果集的當前行檢索一行或多行。可以對結果集當前行做修改。一般不使用游標,但是需要逐條處理數據的時候,游標顯得十分重要。

題目補充
1.寫一個sql將表TEST_A(ID,NAME,CODE)中重復次數大于2的NAME值打印出來(15)
select NAME from TEST_A
where NAME in(select NAME from TEST_A group by NAME having count(NAME)>2);

2.寫一段代碼獲取結構 List<Map<String,String>>中各個Map,并通過System.out.println()打印出來(15)
/**
 * 將指定的 結構為 List<Map<String,String>>的參數 通過System.out.println()打印出來
 * 格式:"鍵名:鍵值"
 * @param List<Map<String,String>>
 *
 */
public void printOut(List<Map<String,String>>){

    List<Map<String,Object>> list= List<Map<String,String>>
    for (int i=0;i<list.size(),i++)
    {
    Map map=(Map)list.get(i);
    Iterator iterator = map.keySet().iterator();
    while (iterator.hasNext())
    {
    String key = (String) iterator.next();
    Object object = map.get(key);
    }
    }
}

3.有類似這樣的一串字符"abcddeffx.asre-321!assra..",請實現以下方法將字符串各個字符的出現的次數統計出來
/**
 * 將指定的 結構為 List<Map<String,String>>的參數 通過System.out.println()打印出來
 * 格式:"鍵名:鍵值"
 * @param List<Map<String,String>>
 * @return Map<字符,出現的次數>
 */
 public Map<Character,Integer> staticCharcnt(String str){

 }

4.在一個文本文件(文件大小不超過2k)中存放了很多以空格分隔的英語單詞,請寫一段偽代碼或用文字描述來實現,已得到沒有重復的、且按字典順序排序的所有單詞(20分)

首先實現做一個SortedMap,這個Map的Comparator是根據字母順序排列的一個規則.



5.請用javascript語言解析如下json對象,取出對象中所有數據或將其顯示在頁面上。(15)
var user = {
    "username" : "andy",
    "age" : 25,
    "info" : {"tell":"123","cellphone":"13766"}
    "address" : [
                    {"city":"北京建國門大街"}
                    {"city":"天津海泰信息廣場"}
                ]
}

<table border="1">
    <tr>
        <td>user.username</td>
        <td>user.age</td>
        <td>user.info.tell</td>
        <td>(user.address[0].city</td>
        <td>user.address[1].city</td>
    </tr>
</table>


6.在項目中一導入jquery1.7庫,請實現用jquery查找下列表格的第二行第三列的值。(15)

<table id= "tab">
    <tbody>
        <tr>
            <td>第一行第一列</td>
            <td>第一行第二列</td>
            <td>第一行第三列</td>
            <td>第一行第四列</td>
        </tr>
        <tr>
            <td>第二行第一列</td>
            <td>第二行第二列</td>
            <td>第二行第三列</td>
            <td>第二行第四列</td>
        </tr>
    </tbody>
</table>
$('#tab tr').eq(1).find('td').eq(2)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容