cse114 official midterm 1

cse114 official midterm 1 - CSE 114 Midterm Exam 1 Monday,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 114 Midterm Exam 1 Monday, March 10, 2008 NAME (please print legibly): Your University ID Number: Your Recitation Number: Please use a pen for all answers. Write all of your answers on the attached answer sheet. No books or notes can be used during the exam. Any CHEATING will result in an F as well as being written-up on academic dishonesty. The last page includes a list of useful methods. NO BS bonus: If you do not know the answer to a problem and leave it blank you will receive 1 point for each part (e.g., a,b,c, etc.) that you leave blank. If you write anything in the space and it is wrong, you will receive a 0. You will not lose points for small coding details. 1 1. (6 points) We want to write a program that will print all is well on 100 different lines. How can we implement this with a while loop? (a) int a = 0; while (a < = 100) { System.out.println(all is well); a++; } (b) int a = 1; while (a < 100) { System.out.println(all is well); a++; } (c) int a = 0; while (a < 100) { System.out.println(all is well); a++; } (d) while (int a = 0; a < 100; a++) System.out.println(all is well); 2. (6 points) True or false? The following two if-else statements are completely equivalent: if (a < b) System.out.println("less"); else System.out.println("more"); if (a > b) System.out.println("more"); else System.out.println("less"); 2 3. (6 points) What is the result of this Java statement? int foo = 5.2 / 2; (a) The answer will be rounded from 2.6 to 3 and stored in foo (b) The answer will be truncated to 2 and stored in foo (c) The compiler will generate an error message (d) None of the above 4. (6 points) Which one of the following choices correctly defines a Java method named transform that takes a String as its argument and returns a String ? (a) public transform (String x) returns String (b) public String transform (String s) (c) public transform ( String input, String output) (d) None of the above 5. (6 points) Assume getAge is a method of the Person class and Katie is a Person object. Which of the following represents a valid method call?following represents a valid method call?...
View Full Document

Page1 / 10

cse114 official midterm 1 - CSE 114 Midterm Exam 1 Monday,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online