Java Programming 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?

  • Method, Function, Loop
  • Class, Object, Interface
  • If, Else, Switch
  • Sequence, Selection, Iteration (correct)
  • Which control structure is used to choose between alternative courses of action?

  • Selection (correct)
  • Switch
  • Sequence
  • Iteration
  • What determines the order in which statements or instructions are carried out in a Java program?

  • Control Structures (correct)
  • Variables
  • Operators
  • Data Types
  • Which keyword is used for the selection structure in Java?

    <p>if</p> Signup and view all the answers

    What type of control structure is used for executing instructions repeatedly until a logical condition is satisfied?

    <p>Repetition/Iteration</p> Signup and view all the answers

    In a Java program, which control structure is used when one group of statements is selected from several available groups?

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

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

    <p>The statements following the if are not executed</p> Signup and view all the answers

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

    <p>&gt;=</p> Signup and view all the answers

    In Java, what is the syntax for the if statement?

    <p>if (expression) { statement; }</p> Signup and view all the answers

    What should be done after the if statement in Java to maintain proper code indentation?

    <p>3 space indentation</p> Signup and view all the answers

    Which symbol is used in Java to check for equality between two values?

    <p>==</p> Signup and view all the answers

    What does the following code do: if (balance > 0) { fee = 0; } ?

    <p>Sets fee to 0 if balance is positive</p> Signup and view all the answers

    What does the following code do: if (hrsWked > 38) { System.out.print('Overtime hours: ' + (hrsWked - 38)); } ?

    <p>Prints 'Overtime hours' with the difference of hrsWked and 38</p> Signup and view all the answers

    What does the following code do: if (length == width) { System.out.print('it is square'); } ?

    <p>Checks if length is equal to width</p> Signup and view all the answers

    What does the following code do: if (totalPrice >= 100) { disc = totalPrice * 0.1; totalPrice = totalPrice - disc; } ?

    <p>Calculates total price after applying a discount of 10%</p> Signup and view all the answers

    'Java Math Notation Description' mentions which operator for 'Greater than or equal to'?

    <p>≥</p> Signup and view all the answers

    More Like This

    Use Quizgecko on...
    Browser
    Browser