English

Explain the usage of IF Statement in Java.

Advertisements

Question

Explain the usage of IF Statement in Java.

Explain
Advertisements

Solution

The if statement in Java is a decision-making or conditional statement used to execute a block of code only when a specified condition is true. It allows the program to make decisions and control the flow of execution based on a condition.

Working of the if Statement

  1. The if statement evaluates a condition that produces either true or false.
  2. If the condition is true, the statements inside the if block are executed.
  3. If the condition is false, the statements inside the if block are skipped.
  4. After executing or skipping the if block, program control moves to the next statement.

Syntax:

if (condition)
{ 
}

shaalaa.com
  Is there an error in this question or solution?
Chapter 7: Statements and their Scope - EXERCISE [Page 163]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 7 Statements and their Scope
EXERCISE | Q 9. | Page 163
Advertisements
Share
Notifications



      Forgot password?
Use app×