KnowledgeBoat Logo

Computer Applications

What is a compound statement? Give an example.

Java Conditional Stmts

16 Likes

Answer

Two or more statements can be grouped together by enclosing them between opening and closing curly braces. Such a group of statements is called a compound statement. For example,

if (a < b) {
            
    /*
    * All statements within this set of braces 
    * form the compound statement
    */

    System.out.println("a is less than b");
    a = 10;
    b = 20;
    System.out.println("The value of a is " + a);
    System.out.println("The value of b is " + b);
            
}

Answered By

9 Likes


Related Questions