Programming in Java: If Statement

in #technology6 years ago

One of the most important things to learn in programming is the "if statement".

This is used a lot in programming and should come as second nature to all programmers.

The "if statement" is composed of two things the "if" and the "else."

The "if" checks the condition stated within it and the "else" catches the other condition which does not fall under the first condition.

In the example above there is an example for the if statement.

The program takes a number value from the user. Then the if statement check to see if the value is 9 or not.

If the value is 9 the statement "Your number is 9" prints.

And if the value is not 9 the statement "Your number is not 9" prints.


The picture above is the output to the program.

For the first part I gave the program the number 9 so it printed the statement "Your number is 9".

And for the second part I gave the program the number 10 so it printed the statement "Your number is 10".

And that is how if statement logic works, it is a fairly easy concept to learn and has many applications in programming.