Advertisement
Guest User

Untitled

a guest
Nov 15th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class SimpleCalc {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.  
  8.         while (in.hasNext()) {
  9.             int n = in.nextInt();
  10.            
  11.             boolean cp = false;
  12.             for (int i = 0; i < n; i++) {
  13.                 if (cp == true)
  14.                     System.out.println();
  15.                 cp = true;
  16.                 int x = in.nextInt();
  17.                 double a0 = in.nextDouble();
  18.                 double af = in.nextDouble();
  19.  
  20.                 double a1 = 0;
  21.  
  22.                 double c = 0;
  23.                 double k = 0;
  24.                 for (int j = 0; j < x; j++) {
  25.                     c = in.nextDouble();
  26.                     c = (double) (-1)
  27.                             * ((double) 2 * (double) (x - j) * (double) c );
  28.  
  29.                     k = (double) c + (double) k;
  30.  
  31.                 }
  32.                 k=(double)k/(double)(x+1);
  33.                 a1 = ((double) (x * a0) + af) / (double) (x + 1) + (double) k;
  34.                 System.out.printf("%.2f\n", a1);
  35.  
  36.             }
  37.            
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement