Computer Science, asked by megharidhi14t, 11 months ago

program to illustrate the working of switch in the presence of break statements ?

Answers

Answered by BrainlyMOSAD
235
answer :

Import
java.util.scanner;
Public class main
{
Public static void main(string args[])
{
Scanner sc =new scanner (system.in);
Int age;
age=7:
switch(age)
{
Case1:
system.out.println("you are crawl");
break;
case2:
system.out.println("you can get in trouble");
break;
default:
system.out.println("I donot know how old you are");
break;
}
}
}

Regards
rishi Arya .co

myankagrawal123: great explained sir
arshu15: ▄︻̷̿┻̿═━一 osssm ans buddy
meghakatiyar1: Bhai bahut mast answer PR hamhe samaj nhi aaya
BrainlyMOSAD: this is my first program total 37 minutes taken . some user not understand its typically based on computer science engineering questions . thnk to all . this is my last edit.
Brainlytrainer: fbls
Brainlytrainer: answer
SwaggerQueen: That's My swt Bro's answering style rishu ,,, Grt bhai
Answered by siddhartharao77
109

Switch statement:  It is one of decision-making control flow statements.

Now, I am gonna illustrate the switch case with and without break statements.

(i)

Switch With break statements: - Default one:

#include<stdio.h>

int main()

{

int a = 2;

switch(a)

{

case 0:

printf("A");

break;

case 1:

printf("B");

break;

case 2:

printf("C");

break;

default:

printf("D");

break;

}

return 0;

}


Output: C

Reason: Here, i have used break statement to break the flow of control of every case block.

-------------------------------------------------------------------------------------------------------------

(ii)

Switch without break statements:

#include<stdio.h>

int main()

{

int a = 2;

switch(a);

{

case 0:

printf("A");

case 1:

printf("B");

case 2:

printf("C");

default:

printf"(D");

}

return 0;

}


Output : CD

Reason: Here, with the absence of break statement, all the statements below the matched case gets executed.



Hope this helps!


AliaaBhatt: fab answer☺
siddhartharao77: Thanks to alllllll :-)
Anonymous: (-:
siddhartharao77: :-)
TheUrvashi: If Oscars were given for a well done job , I’d nominate you! Really its just fantastic answer.......Bro...Keep it Up
akhlaka: Excellent answer sir... :)
siddhartharao77: Thank you sis
akhlaka: always welcome bhaiya... :)
silu12: nice
siddhartharao77: thank u!
Similar questions