股票雷达Raquant笔试题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了股票雷达Raquant笔试题相关的知识,希望对你有一定的参考价值。
空闲之作,相互学习^_^
题目要求:
1、生成五千行文本文件;
2、其中每一行分成3列,每一列是一个随机数,取值1到100的整数;
3、读取生成的文件,算出三列全是偶数的行数与三列全是奇数的行数的比值;
4、重复1到3的步骤,重复50遍,打印出50个数,计算这50个数的标准差。
1 public class testWork { 2 3 // 得50个数 4 public double[] db() { 5 6 int evenNum = 0; 7 int oddNum = 0; // jishu 8 9 int count_all_even = 0; 10 int count_all_odd = 0; 11 12 int arr[][] = new int[5000][3]; 13 double db[] = new double[50]; 14 15 for (int h = 0; h < 50; h++) { 16 System.out.println("第"+(h+1)+"遍输出5000行数据"); 17 for (int i = 0; i < 5000; i++) { 18 19 for (int j = 0; j < 3; j++) { 20 21 arr[i][j] = (int) (Math.random() * 100); 22 23 if (j == 2) { 24 System.out.println(arr[i][0] + " " + arr[i][1] + " " 25 + arr[i][2]); 26 } 27 28 if (arr[i][j] % 2 == 0) { 29 evenNum++; 30 } else { 31 oddNum++; 32 } 33 } 34 35 // System.out.println(evenNum + " " + oddNum); 36 37 if (evenNum == 3) { 38 count_all_even++; 39 } 40 if (oddNum == 3) { 41 count_all_odd++; 42 } 43 44 evenNum = 0; 45 oddNum = 0; 46 47 } 48 // System.out.println(count_all_even + " " + count_all_odd); 49 db[h] = (double) count_all_even / count_all_odd; 50 // System.out.println("第"+(h+1)+"遍count_all_even / count_all_odd的比值为" + " : " + db[h]); 51 52 count_all_even = 0; 53 count_all_odd = 0; 54 } 55 return db; 56 } 57 58 // 获取平均值 59 public double getAverage(double db[]) { 60 int sum = 0; 61 for (int i = 0; i < db.length; i++) { 62 sum += db[i]; 63 } 64 return (double) (sum / db.length); 65 } 66 67 // 获取标准差 68 public double getStandardDevition(double db[]) { 69 double sum = 0; 70 for (int i = 0; i < db.length; i++) { 71 sum += Math.sqrt(((double) db[i] - getAverage(db)) 72 * (db[i] - getAverage(db))); 73 } 74 return (sum / (db.length - 1)); 75 } 76 77 public static void main(String[] args) { 78 79 testWork tw = new testWork(); 80 81 double x = 0.0; 82 83 double db[]=tw.db(); 84 85 for(int i=0;i<50;i++){ 86 System.out.println("第"+(i+1)+"遍count_all_even / count_all_odd的比值为" + " : " + db[i]); 87 } 88 89 x = tw.getStandardDevition(db); 90 System.out.println("50个数的标准差为: "+x); 91 } 92 93 }
结果如下:
以上是关于股票雷达Raquant笔试题的主要内容,如果未能解决你的问题,请参考以下文章