zoukankan      html  css  js  c++  java
  • 第十二周课上练习

    课上实验

    sort的学习

    import java.util.*;
    import java.lang.*;
    public class MySort {
        public static void main(String[] args) {
            String[] toSort = {"aaa:10:1:1",
                    "ccc:30:3:4",
                    "bbb:50:4:5",
                    "ddd:20:5:3",
                    "eee:40:2:20"};
    
            int [] tmp = new int [toSort.length];
            int val;
            String [] s;
    
            System.out.println("Before sort:");
            for (String i : toSort) {
                System.out.println(i);
    
            }
    
            for(int i = 0; i < toSort.length; i++) {
                s = toSort[i].split(":");
                tmp[i] = Integer.parseInt(s[3]);
            }
            Arrays.sort(tmp);
    
            System.out.println("After sort:");
            for(int i = 0; i < toSort.length; i++)
                for(int j = 0; j < toSort.length; j++){
                    s = toSort[j].split(":");
                    val = Integer.parseInt(s[3]);
                    if(val == tmp[i]) {
                        System.out.println(toSort[j]);
                    }
                }
        }
    }
    

    test

    import org.junit.Test;
    import java.util.Arrays;
    import static org.junit.Assert.*;
    public class StringArrayDemoTest {
        String s1 = "abcde";
        String s2 = "aaa:bbb:ccc";
        String[] a1 = {"aaa","bbb","ccc"};
        int [] c1 = {2,5,3,4};
        char [] c2 = {'a','b','c','d'};
    
        @Test
        public void charAt() throws Exception {
            assertEquals('a',s1.charAt(0));
            assertEquals('e',s1.charAt(4));
        }
    
        @Test
        public void split() throws Exception {
            assertEquals(a1,s2.split(":"));
        }
    
        @Test
        public void sort() throws Exception{
            Arrays.sort(c1);
            assertEquals(5,c1[3]);
        }
    
        @Test
        public void binarySearch() throws Exception{
            int c;
            c = Arrays.binarySearch(c2,'c');
            assertEquals(2,c);
        }
    }
    

    面临问题:不知道指令的确切意思,通过用idea不断地debug,不断地纠正我的Test类

  • 相关阅读:
    推荐系统(二)
    应用高斯分布来解决异常检测问题(三)
    应用高斯分布来解决异常检测问题(二)
    应用高斯分布来解决异常检测问题(一)
    高斯(正态)分布、GDA、Mixtures of Gaussian
    主成分分析
    logistic回归
    推荐系统(一)
    基于朴素贝叶斯模型的文本分类
    K均值聚类算法
  • 原文地址:https://www.cnblogs.com/panyinghao/p/6852812.html
Copyright © 2011-2022 走看看