Вы находитесь на странице: 1из 2

Name:_____________________ ICS3U Date:_____________________

Review:
Terminology to know:
Boolean Expression Pseudorandom
Compound Boolean Expression Short Circuit Evaluation
Conditional Control Structure Truth Table
AND OR NOT Seed
Nested Loop structure

1. Use decision structure to display the appropriate statement for each of the following:
a) Display “Great Job!” when a grade is 95 or higher
b) Display “Error” when number is less than 20 or greater than 50
c) Add 2 to the value of y when y is less than 100

2. Assume that num1 and num2 contain integer values. Write an if-else if statement that displays
one of the following messages as appropriate
First number is larger
Second number is larger
Numbers are equal

3. Which is the appropriate word, odd or even, for the blanks below:
if (num%2==0){
System.out.println(“______ Number”);
} else {
System.out.println(“______ Number”);
}

4. Write an expression that includes the nextInt() method for each of the following situations:
a) Generate a random integer between 1 and 50
b) Generate a random integer between 20 and 100
c) Generate a random double between 10 and 20

5. Identify the logic errors in the statements below, which should display a single appropriate
message for any value of age:
if (age < 18){
System.out.println(“Child”);
} else if (age > 18 && age < 65) {
System.out.println(“adult”);
} else if (age > 65) {
System.out.println(“senior”);
}

-1-
Name:_____________________ ICS3U Date:_____________________

6. Determine if each of the following evaluates to true or false:


size = 100 weight = 50 value = 75
a) !(value < 75)
b) !(size < 100 && weight > 50 && value > 75)
c) (value < 125 || weight < 76) && size == 100

7. Write the code that will return the absolute value of a number. Check your answer by using the
absolute value function in the math class.

1
8. Write a program that will solve for values in the quadratic equation: 𝑦 = 2 (𝑥 + 3)2 − 4.
The program should ask the user whether they want to solve for 𝑥 or for 𝑦. Once the user select
which variable to solve for the program should ask for the user to enter a value.
Sample:
The quadratic equation is: y=(1/2)(x+3)^2 – 4
Enter 1 to solve for y, enter 2 to solve for x: 1
Enter x value: 1
The corresponding y value is: 4
The point is (1, 4)

The quadratic equation is: y=(1/2)(x+3)^2 – 4


Enter 1 to solve for y, enter 2 to solve for x: 2
Enter y value: 4
The corresponding x value(s) is/are: 1, -7
The points are (-7, 4) and (1, 4)

9. What is the difference between a while statements and a do-while statement?

10. What is an infinite loop? What type of error can lead to an infinite loop?

11. How many times will the do-while loop execute?


int x = 0;
do {
x = x + 2;
} while (x < 120);

-2-

Вам также может понравиться