hw5 - if (r1 == r2) System.out.println("Rectangles...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 302 Homework 5 - Due Wednesday, July 6 Name: 1. The following piece of code has three errors. Circle each of the errors, and also describe how you would Fx each error. Assume that x and y are variables of type int and have already been declared and initialized. if (x = 4) if (5 <= y <= 7) System.out.println("x is 4, and y is close to 6"); else System.out.println("x is not 4"); 2. What is wrong with the following code and how would you Fx it? Rectangle r1 = new Rectangle(5,4,6,8); r1.translate(1,2); Rectangle r2 = new Rectangle(6,6,6,8);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (r1 == r2) System.out.println("Rectangles match"); else System.out.println("Rectangles don’t match"); 3. Translate the following switch statement into an sequence of if/else if/. ../else. You may asumme that i and x are variables of type int and have already been declared and initialized. switch(i) { case 0: x = 5; break; case 2: x = 4; break; case 4: x = 7; break; default: x = 10; break; } 4. Evaluate the boolean expression (true || true && false) && (!(false || true) || true) :...
View Full Document

This note was uploaded on 08/08/2008 for the course CS 302 taught by Professor Willbenton during the Spring '07 term at University of Wisconsin.

Ask a homework question - tutors are online