Morash
04-17-2014, 01:01 AM
Calculator In Java Using Switch Statement
The switch Statement Is Used As A Reciprocal Of nested if else Statements. It Is Used When Multiple Choices Are Given And One Choice Is To Be Selected.
The 'nested if-else' Structure Becomes Complicated In Multiple Choices So Then We Used switch Statement.
One Of The Choices Or Cases In The switch Statement Is Executed Depending Upon The Value Returned By The Expression.
In The switch Statement The break Statement Is Normally Used At The End Of Statements In Each Case. It Exits The Control From The Body Of switch Structure.
If It Is Not Used Then The Statements Of Other Cases That Come After The Matching Case Will Also Be Executed.
Syntax
switch(expression)
{
case constant:
statement;
break;
}
Example Of Making A Calculator
http://i57.tinypic.com/2rh1lzb.jpg
Output
Addition
http://i60.tinypic.com/2uf3re1.jpg
Subtraction
http://i61.tinypic.com/2cpumj9.jpg
Multiplication
http://i58.tinypic.com/24p02l2.jpg
Division
http://i58.tinypic.com/2iviipw.jpg
The switch Statement Is Used As A Reciprocal Of nested if else Statements. It Is Used When Multiple Choices Are Given And One Choice Is To Be Selected.
The 'nested if-else' Structure Becomes Complicated In Multiple Choices So Then We Used switch Statement.
One Of The Choices Or Cases In The switch Statement Is Executed Depending Upon The Value Returned By The Expression.
In The switch Statement The break Statement Is Normally Used At The End Of Statements In Each Case. It Exits The Control From The Body Of switch Structure.
If It Is Not Used Then The Statements Of Other Cases That Come After The Matching Case Will Also Be Executed.
Syntax
switch(expression)
{
case constant:
statement;
break;
}
Example Of Making A Calculator
http://i57.tinypic.com/2rh1lzb.jpg
Output
Addition
http://i60.tinypic.com/2uf3re1.jpg
Subtraction
http://i61.tinypic.com/2cpumj9.jpg
Multiplication
http://i58.tinypic.com/24p02l2.jpg
Division
http://i58.tinypic.com/2iviipw.jpg