



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A java midterm exam from the computer science and engineering (cse) department, taken in the fall semester of 2011. The exam covers various topics such as operator precedence, java identifiers, class definitions, and method invocations. It includes multiple-choice questions, programming exercises, and coding tasks.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




public class While { public static void main( String[] args ) { final int MAX = 9, MIN = 5; int i = 7, j = 8;
while ( i <= MAX ) { while ( j > MIN ) { ++j; System.out.println( i + " " + j ); j -= 4; } i++; j = i; }
System.out.println( i + " " + j ); } }
int x = 5, y = 3, z; boolean bool1 = !((x > 4) || (y <= 6)) == ((y <= 4) && !(x > 6));
if ( x++ >= 4 || --y >= 3 ) z = x++ + --y; else z = ++x + y--;
int a = 5, b = 3, c; boolean bool2 = !(b > 4) && (a <= 6) && (a <= 4) || (b > 6);
if ( a++ >= 4 && --b >= 3 ) c = a++ + --b; else c = ++a + b--;
bool1 =
x =
y =
z =
bool2 =
a =
b =
c =
this.a = ________
Test3.b = ________
this.c = ________
c = ________
b = ________
a = ________
this.a = ________
Test3.b = ________
this.c = ________
x = ________
a = ________
b = ________ c = ________
result = ________
this.a = ________ Test3.b = ________
this.c = ________ x = ________
a = ________
b = ________ c = ________
1 public class Test 2 { 3 private int a; 4 private static int b = 2; 5 private int c;
6 public static void main( String[] args ) 7 { 8 Test3 ref = new Test3( 3 );
9 ref.method1( ref.a ); 10 }
11 public Test3( int a ) 12 { 13 this.a = a; 14 }
15 public void method1( int x ) 16 { 17 int c = x--; 18 int b;
19 b = a + 2; 20 a = c + 3;
21 System.out.println( "this.a = " + this.a ); 22 System.out.println( "Test3.b = " + Test3.b ); 23 System.out.println( "this.c = " + this.c ); 24 System.out.println( "c = " + c ); 25 System.out.println( "b = " + b ); 26 System.out.println( "a = " + a ); 27 System.out.println( "result = " + method2( b + c ) ); 28 System.out.println( "this.a = " + this.a ); 29 System.out.println( "Test3.b = " + Test3.b ); 30 System.out.println( "this.c = " + this.c ); 31 System.out.println( "x = " + x ); 32 System.out.println( "a = " + a ); 33 System.out.println( "b = " + b ); 34 System.out.println( "c = " + c ); 35 }
36 private int method2( int x ) 37 { 38 int b = x; 39 int c = this.c + Test3.b;
40 x = a = b + c;
41 System.out.println( "this.a = " + this.a ); 42 System.out.println( "Test3.b = " + Test3.b ); 43 System.out.println( "this.c = " + this.c ); 44 System.out.println( "x = " + x ); 45 System.out.println( "a = " + a ); 46 System.out.println( "b = " + b ); 47 System.out.println( "c = " + c );
48 Test3.b = b + 2; 49 this.c = a + c;
50 return x + 5; 51 } 52 }
int mystery( int a ) { int b = a - 2;
if ( b >= 7 ) { System.out.println( a + " " + b ); a = b - mystery( b + 1 ); } else { System.out.println( "Stop" ); b = a + 2; }
System.out.println( a + " " + b ); return a + b; }
public void f5( int x ) { int y = 0;
if ( x <= 1 ) y = 3; if ( x <= 2 ) y = 5; if ( x == 3 || x >= 4 ) y = 7; else y = 9;
System.out.println( y ); }
public void f5( int x ) { int y = 0;
if ( x <= 1 ) y = 3; else if ( x <= 2 ) y = 5; else if ( x == 3 || x >= 4 ) y = 7; else y = 9;
System.out.println( y ); }