Term 1: QUIZ 2

Ace your homework & exams now with Quizwiz!

What is output to the screen by the following code? int x = 29 % 10; if (x > 10) System.out.println(1); else if (x > 8) System.out.println(2); else if (x > 6) System.out.println(3); else if ( x > 4) System.out.println(4); else System.out.println(5);

2

To test if a grade is a C (between 70 and 79 inclusive) you would use the following if statement: if ( g ______ 70 ______ g ______ 79) What three sets of symbols correctly fill in the blanks?

>=, &&, <=

What are if statements used for in programs?

Making decisions

What does the following code do? if (month == 4) if (day <= 21) System.out.println("Aries");

Tests if month is 4 and day is less than or equal to 21.

A && (A || B)

The following truth table matches which boolean condition?

Given the variables, which boolean condition is true? int a = 5; int b = 5;

b >= a || a >= b

Which if statement below tests if letter holds J? ( letter is a char)

if (letter == 'J')

Consider the following code: if ( !(val >= 80 && val < 90) ) Which of the following produces the same output?

if (val < 80 || val >= 90)

Consider the following code: int x = 8; int y = 17; if (x != y) System.out.print ("one"); else if (x > y) System.out.print ("two"); else if (y < x) System.out.print ("three"); else if (y >= x) System.out.print("four"); else System.out.print("five"); What is the output?

one

Consider the following expression. Assume that x and y are properly initialized boolean variables. (x && y) || !(x || y) The result of evaluating the expression above is best described as:

true only when x and y have the same value


Related study sets

Which of the following are never true of an object that is at equilibrium? Include all that apply.

View Set

(WORK IN PROGRESS) Big O Notation and Sorting Algorithms | Comp Sci AP

View Set

Health : 2. Physical Health (BENEFITS OF PROPER NUTRITION)

View Set

Microeconomics Exam 1 - Chapter 3

View Set

temporary compromise (unit: rising tensions)

View Set