exerciseFeb108 - the class, your program should display:...

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

View Full Document Right Arrow Icon
COMP202 Instructor: Ladan Mahabadi February 1, 2008 Which of the following is syntactically correct? int x = 10; int y = 20; boolean equalValues = false; if (x == y)                  if (x = y)  if(x) if (equalValues) { { { { ..… } } } } Parameter Passing in Java What are the values displayed after compiling and running the following? public class Test { public static void main(String[] args) { int testVariable = 2; addOne(testVariable); System.out.println(“value of testVariable is:” + testVariable); } Public static void addOne(int inputValue) { inputValue++; System.out.println(“Inside addOne; parameter inputValue ‘s:”+ inputValue); } } Infinite Classroom
Background image of page 1

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

View Full DocumentRight Arrow Icon
Imagine there‘s a class with an infinite number of seats with the restriction that each row has 5 seats in it. Write a program that prompts the user to enter the number of students and then proceeds as announcing the seat numbers of the students. For instance, if there are 8 students in
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the class, your program should display: Seat 1, Seat 2, Seat 3, Seat 4, Seat 5 Seat 1, Seat 2, Seat 3 Guess in 20 Questions with a Twist Write a program that generates a random integer r between 1 and 20. Then it prompts the user to guess a value. At each step, your program should compare the user-entered value with r and announce: “larger, smaller, or You win!” if the guessed value is larger, smaller or equal to r respectively. The only catch is that the user is restricted to alternate his guesses between even and odd numbers. In other words, if his first value is an odd number, in the next step he has to choose an even number and so on. Ensure that your program restricts the user to do so. End the game in 20 steps and announce “You Lose!” if the user doesn’t win by then....
View Full Document

This note was uploaded on 04/14/2008 for the course COMP 202 taught by Professor Verbrugge during the Winter '07 term at McGill.

Page1 / 3

exerciseFeb108 - the class, your program should display:...

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

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