Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class SredniaArytm
- {
- public static void main(String[] args) throws FileNotFoundException
- {
- Scanner in = new Scanner(new File("dane.txt"));
- double wynik = 0;
- Scanner in2 = new Scanner(new File("niepewnosci.txt"));
- double niepewnosc = 0;
- int n = 0;
- System.out.print("Podaj ilosc liczb w pliku: ");
- Scanner in3 = new Scanner(System.in);
- n = Integer.parseInt(in3.nextLine());
- in3.close();
- double[] liczby = new double[n];
- for (int i = 0; i < n; i++)
- {
- liczby[i] = Double.parseDouble(in2.nextLine());
- }
- in2.close();
- wynik += Double.parseDouble(in.nextLine());
- boolean firstTime = true;
- for (int i = 1; i < n; i++)
- {
- wynik += Double.parseDouble(in.nextLine());
- if (firstTime)
- {
- niepewnosc = dNiepewnosc(liczby[i-1], liczby[i]);
- firstTime = false;
- }
- else
- niepewnosc = dNiepewnosc(niepewnosc, liczby[i]);
- }
- in.close();
- wynik /= n;
- niepewnosc = Math.abs(niepewnosc/n);
- System.out.println("Wynik: " + wynik + " ± " + niepewnosc);
- }
- public static double dNiepewnosc(double x, double y) {return Math.sqrt(Math.pow(y,2)+Math.pow(x,2));}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement