{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

exerciseFeb108 - the class your program should display Seat...

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern