If, if..else , if..else..if commentary in Java
If , If…else , nested if commentary in Java
The If commentary in most cases is used to check a situation. It’s used to test whether or not a situation is right or false earlier than executing a commentary.
For instance, it’s possible you’ll wish to take a look at if x is the same as y , if sure then upload x and y or another way.
There are different examples like –
Chances are you’ll wish to permit person to simply sign up their profile provided that they’re of sure age. And the instance is going on and on.
The if commentary is not only about trying out on my own, I might say it’s wanted in each program. In reality, you’ll be able to’t simply let customers input the rest they prefer, there must be regulations and laws, as an example, when you have a sort that permits person to go into their username and telephones quantity, the colon for telephone will have to settle for simplest numbers and if the person does now not observe up with the principles, an error will have to be displayed. That is the place if commentary is in use.
Let’s examine the way it works in Java
Syntax for If commentary
if ( expression ) {
//Remark ;
}
Examples
//by means of Zhullyblog
public magnificence pattern{
public static void primary(String[] args) {
int num = 10;
//take a look at the commentary
if (num > 1){
Machine.out.println(“The quantity is bigger than 1”);
}
}
}
Screenshot
Consequence
If….else commentary
The if else commentary is used to check and in addition go back end result if the situation seems to be false.
Syntax
if ( expression ){
//Remark ;
}
else {
//Remark;
}
Examples
//by means of Zhullyblog
public magnificence pattern{
public static void primary(String[] args) {
int num = 10;
//take a look at the commentary
if (num > 1){
Machine.out.println(“The quantity is bigger than 1”);
}
else {
Machine.out.println(“The quantity is lower than 1”);
}
}
}
Screenshot
Consequence
Let’s transfer
Please percentage