小编use*_*605的帖子

无法得到标准偏差,我做错了什么?

我基本上试图使用一个数组,即从文件中读取的数据,然后使用该数组计算数据的均值和标准差.

我似乎无法得到正确的号码.

static public double[][] calcStats(String[][] x) throws IOException {
  double[][] array = new double[7][2];
  double total = 0, std_dev = 0, amount = 0;
  int row2 = 0;
  for (int row = 1; row < x.length; row++) {
    array[row2][0] = (total);
    array[row2][1] = Math.sqrt(amount);
    amount = 0;
    total = 0;
    if (row >= 2) {
      row2++;
    }
    for (int col = 1; col < x[row].length; col++) {
      total += Integer.parseInt(x[row][col]);
      if (col == 4) {
        total = (total / …
Run Code Online (Sandbox Code Playgroud)

java math

2
推荐指数
1
解决办法
129
查看次数

矢量和使用STL

我是C++和矢量的新手,并试图尝试一些STL函数,我想知道为什么这不起作用.我猜它是因为我的第一个和最后一个位置,他们不被允许成为一个整体吗?

#include <cstdlib>
#include <vector>
#include <iostream>

using namespace std;

/*
 * 
 */
int main() {

    const int lowest = 10;
    const int highest = 99;

    vector<int> scramble;
    for (int i = 0; i < 20; i++){
        scramble.push_back(lowest + rand() % (highest - lowest + 1));
        cout << scramble.at(i) << endl;
    }
    int first = 0;
    int last = 19;

   cout << "The maximum value is: " << max_element(first, last);


}
Run Code Online (Sandbox Code Playgroud)

c++ stl vector

1
推荐指数
1
解决办法
155
查看次数

虽然循环没有终止?

我想知道为什么这个while循环不允许我的程序终止?

据我所知(虽然我可能错了)条件while (cin >> line)检查我的输入流是否为String然后运行我的循环,直到在输入中找不到其他字符串.然而,在测试我的代码后,我得到了正确的输出,但我的循环永远不会终止任何想法为什么?

#include <cstdlib>
#include <iostream>
#include <cctype>

using namespace std;

int main() {

string roman_digits[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
string roman_tens  [] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
string roman_hundreds [] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
string roman_thousands [] = {"", "M","MM", "MMM"};
string line;
char c;


cout << "Type in a Roman numeral: ";

// …
Run Code Online (Sandbox Code Playgroud)

c++ conditional while-loop

0
推荐指数
1
解决办法
1666
查看次数

标签 统计

c++ ×2

conditional ×1

java ×1

math ×1

stl ×1

vector ×1

while-loop ×1