






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
The final exam for the cse 8a course at the university of california, berkeley, given in fall 2010. It includes various java programming questions related to operators, memory allocation, loops, methods, and conditional statements.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







public class F { public static void main( String[] args ) { System.out.println( -1 + 2 - 3 * 10 % 4 ); _________
System.out.println( 2 * 7 - 11 / 9 + 10 ); _________ } }
public class F { public static void main( String[] args ) { int fire = 10, air = 2;
fire = fire * (air + 5); System.out.println( "fire = " + fire ); ________________________
fire = 5 โ air--; System.out.println( "fire = " + fire + "; air = " + air );________________________
fire = 5; air = ++fire + 4; System.out.println( "fire = " + fire + "; air = " + air );________________________ } }
int foo = 42; int bar = 42; boolean foobar = ( foo == bar ); System.out.println( foobar ); ____________ foo = 37; System.out.println( foobar ); ____________
System.out.println( foo == bar ); ____________
this.forward( size );
koko.drawSquare( 42 );
public void fubar() { Pixel[] pixelArray = this.getPixels();
for ( Pixel p : pixelArray ) { p.setRed( 255 ); p.setGreen( 255 ); p.setBlue( 255 ); } }
a = b tmp = a b = tmp;
tmp = a b = tmp; a = b
tmp = a b = a b = tmp;
tmp = a b = a a = tmp;
tmp = a a = b b = tmp;
tmp = b a = b b = tmp;
Picture var1 = new Picture();
_________ var2; // Fill in the type variable var2 should be defined as.
var2 = _______________________ ; // Fill in the right side of this assignment stmt // to get the height of the Picture object var // references.
int i; for ( i = 0; i < 42; ++i ) { System.out.println( i * i );
}
pictureObj.show(); Math.abs( -3 ); turtle1.turnLeft();
FileChooser.pickAFile(); soundObj.play(); ColorChooser.pickAColor();
int width = โฆ ; int height = โฆ ; Pixel p; for ( int j = 0; j < height; j++ ) { for ( int i = 0; i < width; i++ ) { p = getPixel( i, j ); p.setColor( Color.Black ); } }
public void mirrorVertically() { int mirrorPoint = this.getWidth() / 2; Pixel leftPixel = null; Pixel rightPixel = null; Pixel mirrorPixel = null;
for ( int y = 0; y < this.getHeight(); ++y ) { for ( int x = 0; x < mirrorPoint; ++x ) { leftPixel = this.getPixel( x, y ); rightPixel = this.getPixel( this.getWidth() - 1 โ x, y ); mirrorPixel = this.getPixel( mirrorPoint, y ); / MISSING LINE / } } }
int x = 4; int y = 2;
while ( x < 10 && y <= 3 ) { System.out.println( x + " " + y ); x++; y++; }
System.out.println( x + " " + y );
int x = 12; if ( x > 7 ) { x += 3; // Same as x = x + 3; } if ( x >= 15 ) { x += 6; } System.out.println( x );
int x = 12; if ( x > 7 ) { x += 3; // Same as x = x + 3; } else if ( x >= 15 ) { x += 6; } System.out.println( x );
int x = 2; int y = 0;
while ( x < 5 || y <= 1 ) { x++; y++; System.out.println( x + " " + y ); }
System.out.println( x + " " + y );
A) for ( int i = 0; i <= this.getWidth(); i++ )
B) for ( int i = this.getWidth(); i > 0; i-- )
C) for ( int i = this.getWidth() โ 1; i >= 0; i-- )
D) for ( int i = 8; i < this.getWidth(); i++ )
E) for ( int i = this.getWidth() โ 8; i > 0; i-- )
F) for ( int i = -1; i < this.getWidth(); i++ )
public void guess() { int array[] = { 20, 50, 30, 20, 100, 0, 40, 0 };
int a = 200; int b = 0;
for ( int i = 0; i < array.length; i++ ) { int foo = array[i];
if ( foo < a ) { a = foo; b = i; } } System.out.println( a + "," + b ); }
public class F { public static void main( String[] args ) { int x = 5; int y = 8;
System.out.println( false || (y >= 8) ); System.out.println( ++x < y ); System.out.println( true && !(x <= y) ); System.out.println( 4 + x < y ); } }
public void f6( 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 f6( 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 ); }