joapaspe

Chettoo Order growth

Sep 28th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1.     public static void Quiz3() {
  2.    
  3.         int N = 5;
  4.         int []v = new int[N];
  5.         double []t = new double[N];  
  6.         for(int i = 0; i < N; ++i) {
  7.              v [i] = StdIn.readInt();
  8.              t [i] = StdIn.readDouble();
  9.         }
  10.        
  11.         for(int i = 0; i < N; ++i) {
  12.              System.out.println(String.format("%d %f",v[i], t[i]));
  13.              
  14.         }
  15.         //Check the too last
  16.         int last = v.length-1;
  17.         int plast = v.length-2;
  18.        
  19.         double Y = (double) v[plast]/v[last];
  20.         double X = (double) t[plast]/t[last];
  21.        
  22.         System.out.println(""+Y+" "+X);
  23.         // Y**b = X
  24.         // b = log(X)/log(Y)
  25.         double b = Math.log(X)/Math.log(Y);
  26.        
  27.         double a = (double) t[last]/(Math.pow(v[last],b));
  28.        
  29.         System.out.println(b);
  30.         System.out.println(a);
  31.        
  32.         for(int i = 0; i < N; ++i) {
  33.              System.out.println(String.format("%d %f",v[i], Math.pow(v[i],b)*a));
  34.              
  35.         }
  36.         System.out.println(String.format("%.2f",b));
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment