public class firstSemesterExam2012 {
public static void main(){ // Note this program has no compiling or runtime errors.
int i = 0, k = 0, z = 1, n1 = 2, n2 = 2, t = 0;
// Give the values of the variables after the loops have run.
for (i=0; i<=n1; i++){
for (k=0; k<n2; k++){
z += 2;
}
}
System.out.println("1) i = "+i  +";  k = "+k  +";  z = "+z);
//
//1) i = ________    k = ________    z = ________

n1 = 2; n2 = 3; z = 0;
for (i=1; i<=n1; i++){
for (k=1; k<=n2; k++){
z *= k;
}
}
System.out.println("2) i = "+i  +";  k = "+k  +";  z = "+z);
//
//2) i = ________    k = ________    z = ________

n1 = 2; n2 = 2; z = 1;
for (i=1; i<=n1; i++){
for (k=1; k<=n2; k++){
z *= 2;
}
}
System.out.println("3) i = "+i  +";  k = "+k  +";  z = "+z);
//
//3) i = ________    k = ________    z = ________

n1 = 2; n2 = 2; z = 1; t = 17;
for (i=1; i<=n1; i++){
for (k=1; k<=n2; k++){
t++;
z += k * t;
if (z > 3){
z = 2;
break;
}
}
}
System.out.println("4) i = "+i  +";  k = "+k  +";  z = "+z  +";  t = "+t );

//4) i = ________    k = ________    z = ________   t = ________

//_____ 5) To find the number of columns in a 2D array called twoD use the following:
//  a) twoD.length   b) twoD.[0]length   c) twoD[0].length   d) twoD.col

//_____ 6) An array is initialized as follows: int array [ ] = {4, 5, 6, 7}; What is the
//   value stored in array[2] ?

//_____ 7) Which of the following is a logical sub-class for the super class vehicle?
//   a) wheel   b) engine   c) tire  d) car  e) all the answers

//_____ 8) A static method from a different class is called using ________________.
//  a) an object b) an instance  c) a class name  d) a variable

boolean a = true, b = false, c = true, booleanAnswer;
i = 2; k = 4;
double  x = 2.0, y = 3.0, zz = 4.0, doubleAnswer;
// Evaluate the expressions and correctly write the answer in the blank provided.
/* _____  9 */ booleanAnswer = !a && b && i < j && j > k;

/* _____  10 */ booleanAnswer = !a || b || j == k && j != (k - 1);

/* _____  11 */ booleanAnswer = !(a || b || c) && a && i >= k * i % 2;

/* _____  12 */ booleanAnswer = (b || a) && c && (i == j % 2 + 1);

/* _____  13 */ booleanAnswer = !!!(!a && !(b && !c));

/* _____  14 */ booleanAnswer = k != (i * 2 / j % 2) && b;

/* _____  15 */ booleanAnswer = b && (!((b || a) && (a && (!c || (a || (k <= j / i))))));

/* _____  16 */booleanAnswer = b && b || a && !c;

/* _____  17 */booleanAnswer =!c || a || k <= j / i;

/* _____  18 */booleanAnswer = k <= j / (i*i) * 3 % k + j;

/* _____  19 */booleanAnswer =!c || !a || !(k >= j * (j/ i));

/* _____  20 */ intAnswer = ((int)( zz / y + i / k + zz )) % 2;

/* _____  21 */ intAnswer = ((int)( zz / y + zz )) * (i/k) % 3;

/* _____  22 */ intAnswer = (int)( (zz / y)*3 + k / i );

/* _____  23 */ doubleAnswer =  (int) (zz / y + i / k % 2 + zz);

/* _____  24 */ doubleAnswer =  (int) (zz / y) + 42 / ( 221 % 2) * (50002 %2);

/* _____  25 */ doubleAnswer =  (double)i * (i / k);

/* _____  26 */ doubleAnswer =  zz / y *(k %i);

// _____ 27) To find the length of an array called a1 use ________ .
//           a) a1.length( )  b) a1.size( )  c) a1.length   d) a1.last( )  e) all the answers

// _____ 28) To find the length of a String called s1 use _________ .
//           a) s1.length( )  b) s1.size( )  c) s1.length   d) s1.last( )  e) all the answers

// _____ 29) To determine if two strings s1 and s2 are identical use _________ .
//           a) s1.equals(s2)  b) s1 == s2  c) s1 = s2   d) compare(s1, s2)  e) all answers

// _____ 30) Which of the following is a wrapper class?
//           a) int  b) char  c) boolean   d) Integer  e) all the answers

// _____ 31) To find the number of rows in a 2D array called twoD use the following:
//           a) twoD.length   b) twoD.[0]length   c) twoD[0].length   d) twoD.row

// _____ 32) The method calculate1, shown below, calculates numbers that are ________ .
//           a) prime  b) fibanoci  c) even   d) odd  e) divisible by 3

// _____ 33) The method calculate2, shown below, calculates numbers that are ________ .
//           a) prime  b) fibanoci  c) even   d) odd  e) divisible by 3

// _____ 34) The following code segment is found inside a program. It gives a _______ .
//             a) compliling error   b) runtime error   c) logic error
for (int xx=0; xx<3; xx++); {
}
// _____ 35) The following code segment is found inside a program. It outputs ________ .
//           a) hat   b) scat   c) cat   d) compiling error
//           String s1 = "hat";
//           if (s1 = "cat")) s1 = "scat";
//           System.out.println (s1);

// _____ 36) Which of the following classes are automatically included in a Java program?
//           a) String  b) Object  c) Math   d) System  e) all the answers

// _____ 37) Which of the following is a primative data type?
//           a) String  b) Integer  c) Double   d) Character  e) int

// _____ 38) Which of the following data types could an ArrayList hold?
//           a) Integer  b) int  c) double   d) long  e) char

String ss1 = "ABC", ss2 = "aax";
/* _____ 39) */ System.out.println( "39) " + ss1.compareToIgnoreCase ( ss2 ) ) ;
// Note, all methods below compile & run. Write output in blank provided.
/* _____  40 */ System.out.println("40) " + addUp1(3));

/* _____  41 */ System.out.println("41) " + addUp2(4));

/* _____  42 */ System.out.println("42) " + mystry1(3));

/* _____  43 */ System.out.println ("43)");
System.out.println ( mystry2 ( 3, 3 ) );

/* _____  44 */ System.out.println("44) " + calculate1(3));

/* _____  45 */ System.out.println("45) " + calculate2(3));
} /////////////////////////////////
public static int addUp1 (int n){
if (n==1)return 1;
} //////////////////////////////////
public static int addUp2 (int n){
if (n<=1)return 0;
} /////////////////////////////////
public static int addUp3 (int x){
if (x<=1)return 1;
return 1/x;
} /////////////////////////////////
public static int mystry1 (int y){
if (y==0) return 1;
else {
int x = mystry1(y/2);
x *= x;
if (y%2 == 1) x *= 3;
return x;
}
} ///////////////////////////////////
public static int mystry2 ( int x, int y ) {
System.out.print (x + " " );
if ( y <= 1) {
y = x;
x--;
System.out.print ("\n" );
}
if ( x == 1 ) return 1;
return mystry2 ( x, y-1 ) ;
} ///////////////////////////////////////
public static int calculate1 (int x){
int n1=1, n2=1, output = 1;
for ( int q=0; q<x; q++) {
output = n1 + n2;
n1 = n2;
n2 = output;
}
return output;
} //////////////////////////////////////
public static int calculate2 (int x){
int output = 0, count = 0, q, k;
for (q=2; count<x; q++) {
for (k=2; k<q; k++) {
if ( q%k == 0) break;
}
if ( q == k){
output = q;
count++;
}
}
return output;
}    } /////////////////////////////////////////////////////