Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎

2018-11-29

posted Nov 29, 2018, 6:26 AM by Konstantinovich Samuel   [ updated Nov 30, 2018, 6:01 AM ]
Quiz + Discussion on runtime analysis.
//A
public int foo(int [] ary){
    return ary[0];
}


//B
public int foo2(int [] ary){
    int total = 0;
    for( int i=0; i < ary.length; i++){
      total += ary[i];
    }
    return total;
}


//C
public void foo3(int [] ary){
    int total = 0;
    for( int i = 0; i < ary.length; i++){
        for( int j = 0 ; j < ary.length; j++){   
          System.out.println("handshake: "+i+", "+j);
        }
    }
}
Comments