Java Control Structures Quiz
16 Questions
2 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What are the three main control structures in any programming language?

  • Sequence, Selection, Repetition (correct)
  • Selection, Repetition, Sequence
  • Repetition, Selection, Switch
  • Sequence, Iteration, Selection

Which keyword is used for the selection structure in Java?

  • switch
  • if (correct)
  • if/else
  • else/if

What determines the order in which statements are executed in a Java program?

  • Switch structure
  • Sequence structure
  • Control structure (correct)
  • Repetition structure

Which control structure is used to execute instructions repeatedly until a logical condition is satisfied?

<p>Repetition (B)</p> Signup and view all the answers

In a Java program, what determines alternative actions based on different inputs?

<p>'if/else' ladder(chain) (D)</p> Signup and view all the answers

What type of statement is used to choose between alternative courses of action in a Java program?

<p>'if' statement (C)</p> Signup and view all the answers

What happens if the expression in the if statement is false?

<p>The statements following the if are skipped (A)</p> Signup and view all the answers

Which operator is used to check if a value is greater than another value?

<p>&gt; (A)</p> Signup and view all the answers

What is the purpose of the equality operator '=='?

<p>Compare if two values are equal (C)</p> Signup and view all the answers

In Java, the expression 'x < 0' is used to check if the value of x is:

<p>Less than 0 (D)</p> Signup and view all the answers

What does the if statement 'if(balance > 0) { fee = 0; }' do?

<p>Assigns a value of zero to fee if balance is greater than 0 (B)</p> Signup and view all the answers

What does the expression 'hrsWked > 38' check for?

<p>If hrsWked is greater than 38 (A)</p> Signup and view all the answers

In the code 'if(length == width) { System.out.print("it is square"); }', what does it check?

<p>If length is equal to width (B)</p> Signup and view all the answers

What happens if 'totalPrice >= 100' in the code 'if(totalPrice >= 100) { disc = totalPrice * 0.1; totalPrice = totalPrice - disc; }' is true?

<p>A discount of 10% is applied (A)</p> Signup and view all the answers

'3 space indentation' mentioned in the text refers to:

<p>Indenting code blocks by 3 spaces for better readability (A)</p> Signup and view all the answers

'Everything after the if statement should be indented 3 spaces' implies:

<p>'if' statements need to be indented by exactly 3 spaces (C)</p> Signup and view all the answers

More Like This

Use Quizgecko on...
Browser
Browser