Courses‎ > ‎AP Computer Science 2‎ > ‎konstantinovich‎ > ‎


posted Mar 5, 2018, 10:00 AM by Konstantinovich Samuel
Test cases:
Passing the test without extra output is required! 
In general: Only the main should print things, unless otherwise required.

double[] input = {1.0, 2.0, 4.0, 7.0, 10.0, 100.0, 1024.0, -1.0, 0.0};
double[] output = {1.0,1.4142135623730951,2.0,2.6457513110645907,3.1622776601683795,10.0,32.0,-1,0.0};
-1 should throw an exception

int[] input = {0,1,2,3,5,30,40,45,-1};
int[] output ={0,1,1,2,5,832040 ,102334155 ,1134903170 ,-1};

int[] input = {0,1,2,3,4,5,10,11,-1};
int[] output ={1,1,2,6,24,120,3628800,39916800,-1};

public static boolean closeEnough(double a, double b){
    if(a==0.0 && b==0.0)return true;
    if(a==0.0)return Math.abs(b) < 0.00000000001;
    if(b==0.0)return Math.abs(a) < 0.00000000001;
    return Math.abs(a-b)/a < 0.0001;

USACO competition problems 

Start reading both problems carefully so that on Monday we can discuss it.
Read the correct problems. 

These are just general problems – they may use recursion, but then again, they might not.

If you want to work ahead, try the silver on your own over the weekend. I would rather you pair up to discuss and work on the bronze together on Monday. 

On git have the file: 


    in the file have the 2 public methods:

    public static int bronze(String filename);

    public static int silver(String filename);

    I will only test on valid files. Please make sure you test accordingly.

        Test cases:

How should your main look?