Hey friends, welcome to simlplyjavapro!
After you have successfully got the user-input. Well the analysis is perhaps the most interesting part of computer programming. It begins with checking for simple conditions and then it could be extended to any level.
So, lets get started . Java provides you with two tools that help you to analyse your data.
1. The first option is switch-case clause.
when you choose this option you are supposed to follow the syntax given below:
switch(var)
{
case <value 1>: //code for case 1
break;
case <value 2>: //code for case 2
break;
defalut:
//code for the default case
}
Note: When you are using switch case, there are a set of things that you must consider that the variable you use in either int or char.You must ensure to use a break after every case, or
you "FALL THROUGH". Under a fall through the control matches a case , it executes each case that follows without matching for it, unless it finds a break or the end of the switch.
2. The second option is to use if -else clauses:
Syntax:
if (condition)
{
//code block for the case when the condition holds true
}
else
{
//code block for the case when the condition is false
}
Note: The only restriction here is that the condition must be finally a boolean value.
for example : age <25
So that is it !!! In the next post I will share a sample code to implement the clauses mentioned above.
No comments:
Post a Comment