From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Programming conditional logic

Programming conditional logic - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Programming conditional logic

In all programming lanuages writing conditional code is a common practice. Conditional code is commonly called an if then or if else statement. I've already used if statements previously in this course. It's pretty unavoidable. But now I'll go into the details of the if keyword, it's associated keyword, else and how to put these keywords together. I'll start by declaring an integer value named monthNumber and I'll give it a value of eight. Then I'll write some conditional code to evaluate it. I'll start with the keyword if. In order to evaluate a condition you place it within parenthesis. The parenthesis are required. Then you write the condition. I'm going to ask whether the monthNumber is greater than or equal to one and it's less than or equal to three. The double ampersand operator is the logical and. The double pipe character, that's the character on the backslash key, is the logical or. I'll add my braces and then I'll add some output to the console and I'll output the string…

Contents