Exam 6: More Conditionals and Loops

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

How can the following statement be rewritten using a conditional operator? if(x <0) y = x; Else y = 0;

(Multiple Choice)
5.0/5
(26)

If a switch statement contains no break statements at all,

(Multiple Choice)
4.8/5
(40)

Write a declaration that initializes an int variable named num1 to 100 if the boolean variable score is true and to 50 otherwise, using the conditional operator.

(Short Answer)
4.9/5
(42)

What does the break statement do?

(Multiple Choice)
4.8/5
(41)

Rewrite the following nested if-else statements using an equivalent switch statement. if (letter == 'A' || letter == 'a') System.out.println("Excellent"); else if (letter == 'B' || letter == 'b') System.out.println("You can do better"); else if (letter == 'C' || letter == 'c') System.out.println("Try harder"); else if (letter == 'D' || letter == 'd') System.out.println("Try much harder"); else System.out.println("Try another major! ");

(Essay)
4.9/5
(43)

You might choose to use a switch statement instead of nested if-else statements if

(Multiple Choice)
4.9/5
(38)

Given that s is a String, what does the following loop do? for(int j = s.length(); j > 0; j--) System.out.print;

(Multiple Choice)
4.8/5
(33)

Describe a situation where you should use a do loop and a situation where you should use a while loop.

(Essay)
4.8/5
(42)

It is possible to convert any type of loop (while, do, for) into any other.

(True/False)
4.8/5
(41)

A switch statement must have a default clause.

(True/False)
4.8/5
(29)

Given the following tax table information, write Java code to assign the double taxRate appropriately, given the double pay. Select the selection statement (if, if-else, switch) that makes the most sense. If pay is more than 100,000, tax rate is 40% If pay is more than 60,000 and less than or equal to 100,000, tax rate is 30% If pay is more than 30,000 and less than or equal to 60,000, tax rate is 20% If pay is more than 15,000 and less than or equal to 30,000, tax rate is 10% If pay is more than 5,000 and less than or equal to 15,000, tax rate is 5% If pay is less than or equal to 5,000, tax rate is 0%

(Essay)
4.8/5
(36)

Write the code to display an ImageView named the_view at half its original size.

(Essay)
4.7/5
(37)

Each switch statement must terminate with a break statement.

(True/False)
4.8/5
(37)

Rewrite the following if-else statement using a conditional operator. if (x > y) z = x; else z = y;

(Short Answer)
4.9/5
(50)

Given the following code, where x = 0, what is the resulting value of x after the for loop terminates? for(int i = 0; i < 5; i++) X += i;

(Multiple Choice)
5.0/5
(29)
Showing 21 - 35 of 35
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)