Question

Q1: Which of the following is a double-selection control statement? do…while for if…else if. Q2: Which...

Q1: Which of the following is a double-selection control statement?

  1. do…while
  1. for
  1. if…else
  1. if.

Q2: Which of the following is not a Java keyword?

  1. do
  1. next
  1. while
  1. for

Q3: What is output by the following Java code segment?

int temp;

temp = 200;

if ( temp > 90 )

   System.out.println( "This porridge is too hot." );

if ( temp < 70 )

   System.out.println( "This porridge is too cold." );

if ( temp == 80 )

   System.out.println( "This porridge is just right!" );

  1. This porridge is too hot.    
  2. This porridge is too cold.
  3. This porridge is just right!
  4. None of the above.

                                            

Conditional Operator (?:)

Q4: Which of the following is not true about the conditional operator ( ?: )?

  1. The conditional operator is a ternary operator, meaning that it takes three operands.
  2. The first operand is a boolean expression.
  3. The second operand is the result value if the condition evaluates to false.
  4. The second operand is the result value if the condition evaluates to true.

Q5: What is output by the following Java code segment?

int temp = 50;

if ( temp > 90 )

{

   System.out.println( "This porridge is too hot." );

  

   // cool down

   temp = temp – ( temp > 150 ? 100 : 20 );

} // end if

else

{

   if ( temp < 70 )

   {

      System.out.println("This porridge is too cold.");

           

      // warm up

      temp = temp + (temp < 50 ? 30 : 20);

   } // end if

} // end else

if ( temp == 80 )

   System.out.println( "This porridge is just right!" );

  1. This porridge is too hot.
  2. This porridge is too cold.
    This porridge is just right!
  3. This porridge is just right!
  4. None of the above.

Q6: A dangling-else can be clarified by using:

  1. Indentation
  1. Parentheses ()
  1. Braces {}
  1. End-of-line comment //

Q7: The empty statement is denoted with what symbol?

  1. Semicolon ;
  1. Parentheses ()
  1. Braces {}
  1. End-of-line comment //

Q8: Which statement is false?

  1. Both syntax errors and logic errors are caught by the compiler.
  2. Both syntax errors and logic errors have effects at execution time.
  3. Syntax errors are caught by the compiler. Logic errors have effects at execution time.
  4. Logic errors are caught by the compiler. Syntax errors have effects at execution time.

Q9: What is output by the following Java code segment?

int temp;

temp = 180;

while ( temp != 80 )

{

   if ( temp > 90 )

   {

      System.out.print( "This porridge is too hot! " );

      // cool down

      temp = temp – ( temp > 150 ? 100 : 20 );

   } // end if

   else

   {

      if ( temp < 70 )

      {

         System.out.print(

            "This porridge is too cold! ");

           

            // warm up

            temp = temp + (temp < 50 ? 30 : 20);

      } // end if

   } // end else

} // end while

if ( temp == 80 )

      System.out.println( "This porridge is just right!" );

  1. This porridge is too cold! This porridge is just right!
  2. This porridge is too hot! This porridge is just right!
  3. This porridge is just right!
  4. None of the above.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1: -> c. if…else

Eplanation: When the condition is true, it execute some statement and when the condition is false, it execute some other statement.

Q2: -> b. next

Q3: -> a. This porridge is too hot.

Explanation: When the temperature is 200, then only temp > 90 is true and then the statement written under this condition is executed.

Q4: -> c. The second operand is the result value if the condition evaluates to false.

Explanation: The syntax for "?:" conditional operator is given below.

(condition) ? return this if 'condition' is true : return this otherwise

Q5: -> d. None of the above.

Explanation: temp = 50 initially. temp>90 is false, so statement under this condition will not be executed. Then the control will go into else condition. Under else condition, temp<70 is true. So it will print "This porridge is too cold!" and excute the statement "temp = temp + (temp < 50 ? 30 : 20)" which will set the temp to 70. So temp==80 is also false and statements under it will not get excuted. So only "This porridge is too cold!" will be printed.

Q6: -> c. Braces {}

Q7: -> a. Semicolon ;

Explanation: Semicolon actually denotes the end of any statements. If nothing is written before it, then it becomes empty statement.

Q8: -> This question should be  "Which statement is true?".

Ans - c. Syntax errors are caught by the compiler. Logic errors have effects at execution time. This is the only right statement and all others are wrong.

Eplanation: Syntax error happens when you have mistaken in writing the program. It means when you not followed the proper syntax. So at compile time compiler checks for that and will give you the syntax errors made by you. On the other hand logic errors have effect when the program is running(means execution time). Simple example is that you have written a statement to divide and the denominator becomes zero.

Q9: -> b. This porridge is too hot! This porridge is just right!

Explanation: temp = 180 initially. While loop will loop until temp = 80.In the while loop temp > 90 is true so "This porridge is too hot!" will be printed and "temp =  temp – ( temp > 150 ? 100 : 20 );" will be executed which will set temp to 80. Now since the condition in while loop become false, so control will come out of the loop. Now temp == 80 is true, So "This porridge is just right!" will get printed.

Please give feedback.

Add a comment
Know the answer?
Add Answer to:
Q1: Which of the following is a double-selection control statement? do…while for if…else if. Q2: Which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Prelab Exercises Your task is to write a Java program that will print out the following...

    Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...

  • QUESTION 1 Which statement results in the value false? The value of count is 0; limit...

    QUESTION 1 Which statement results in the value false? The value of count is 0; limit is 10. (count != 0)&&(limit < 20) (count == 0)&&(limit < 20) (count != 0)||(limit < 20) (count == 0)&&(limit < 20) 10 points    QUESTION 2 If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5 if (a > b) a = 4; if (...

  • Please create a class in Java that completes the following conditions MorseTree.java /* This program will...

    Please create a class in Java that completes the following conditions MorseTree.java /* This program will read in letters followed by their morse code * and insert them properly in a tree based on the amount of symbols * it has and whether they are left or right descendent. Finally * it prints a few certain nodes. */ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class MorseTree {    public static void main(String[] args) throws FileNotFoundException {        //...

  • 6-1 Test and debug the Invoice Application i need help with this please.. all help is...

    6-1 Test and debug the Invoice Application i need help with this please.. all help is appreciated Source code Java: import java.util.Scanner; import java.text.NumberFormat; public class InvoiceApp { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { // get the input from the user System.out.print("Enter customer type (r/c): "); String customerType = sc.next(); System.out.print("Enter subtotal: "); double subtotal = sc.nextDouble(); // get the discount percent double discountPercent = 0.0; switch(customerType) {...

  • How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the use...

    How do i write the pseudocode for this java code? First, write out pseudocode, and then create a program to help you by accomplishing the following tasks: :  Use command line interface to ask the user to input the following. ○ How many apples are on hand ○ How many apples should be in stock ○ How many oranges are on hand ○ How many oranges should be in stock  Perform an operation to determine how many of...

  • Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games...

    Computer Science 182 Data Structures and Program Design Programming Project #3 – Link List Card Games One of the nice things about Java is it is very easy to do fun things with graphics. The start code provided here will display a deck of cards on the screen and shuffle them. Your mission, is to start with this code and build a card game. Blackjack, poker solitaire, what ever your heart desires. Blackjack is the easiest. Obviously any program you...

  • #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part,...

    #include <iostream> #include <iomanip> #include <vector> using namespace std; Part 1. [30 points] In this part, your program loads a vending machine serving cold drinks. You start with many foods, some are drinks. Your code loads a vending machine from foods, or, it uses water as a default drink. Create class Drink, make an array of drinks, load it and display it. Part 1 steps: [5 points] Create a class called Drink that contains information about a single drink. Provide...

  • While reading the story, consider the culture (or sub culture) and related communication styles the story...

    While reading the story, consider the culture (or sub culture) and related communication styles the story reveals. Consider too, possibly, the values, behavioral norms, social practices, social artifacts, etc. After reading the story through the lens of this idea, please compose a full academic length (evidence-based 7 to 11 sentence long) paragraph which addresses the following prompt: What does the story reveal about the culture it portrays and/OR the communication styles the culture shares? In other words, what does the...

  • Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an...

    Additional code needed: PartA: BurgerOrder class (1 point) Objective: Create a new class that represents an order at a fast-food burger joint. This class will be used in Part B, when we work with a list of orders. As vou work through this part and Part B, draw a UML diagram of each class in using the UML drawing tool 1) Create a new Lab5TestProject project in Netbeans, right-click on the lab5testproject package and select New>Java Class 2) Call your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT