Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void homework(String[] args) {
- TextIO txtIO = new TextIO();
- double stDev = 0.0;
- double mean = 0.0;
- double sum1 = 0.0;
- int num = 0;
- int count = 0;
- double sum = 0.0;
- double[] pole = new double[10];
- boolean end = false;
- while (end == false) {
- String line = txtIO.getLine();
- num++;
- if (line.length() > 0 && TextIO.isDouble(line) == false) {
- System.err.println("A number has not been parsed from line "+ num);
- count--;
- }
- if (line.length() > 0 && txtIO.isDouble(line)) {
- sum = Double.parseDouble(line);
- sum1 += sum;
- pole[count] = sum;
- count++;
- mean = getMean(sum1, count);
- stDev = getVariance(pole, count, mean);
- if(count % 10 == 0){
- System.out.printf("%2d ", count);
- System.out.printf("%.3f %.3f\n",mean ,stDev);
- mean = 0;
- stDev = 0;
- sum1 = 0;
- sum = 0;
- count = 0;
- }
- } else {
- if (line.equals("")) {
- System.err.println("End of input detected!");
- if (count > 1 ) {
- System.out.printf("%2d ", count);
- System.out.printf("%.3f %.3f\n", mean, stDev);
- end = true;
- } else {
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement