Computer Science, asked by sneha6934, 11 months ago

Friends can you give me some JAVA program using the switch case and loop
for class 9.

Answers

Answered by suniltty180
2

In Java, the if..else..if ladder executes a block of code among many blocks. The switch statement can a substitute for long if..else..if ladders which generally makes your code more readable.

The syntax of switch statement is:

switch (variable/expression) {

case value1:

  // statements

  break;

case value2:

  // statements

  break;

  .. .. ...

  .. .. ...

default:

  // statements

}

The switch statement evaluates it's expression (mostly variable) and compares with values(can be expression) of each case label.

The switch statement executes all statements of the matching case label.

Suppose, the variable/expression is equal to value2. In this case, all statements of that matching case is executed.

Notice, the use of break statement. This statement terminates the execution of switch statement. The break statements are important because if they are not used, all statements after the matching case label are executed in sequence until the end of switch statement.


suniltty180: hay
suniltty180: mera dost tumse kuch kahna chahta hai
sneha6934: kya kehna chahata hai
Similar questions