Java Programming Control Structures Quiz

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

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 (D)</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 (B)</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) (C)</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 (C)</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;= (B)</p> Signup and view all the answers

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

<p>if (expression) { statement; } (D)</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 (B)</p> Signup and view all the answers

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

<p>== (B)</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 (D)</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 (A)</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 (D)</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% (D)</p> Signup and view all the answers

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

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

Flashcards are hidden until you start studying

Related Documents

Week 3 If Control Structure.pdf

More Like This

Use Quizgecko on...
Browser
Browser