Using if statements
Once we've sectioned off our two system.out.println statements, we're now ready to provide cases that must be true if these statements are to run. To do this, we preface our new sections with the Java if statement, where if is a Java keyword and it's followed by two parentheses between which we put the statement to be evaluated. If Java determines that the statement we write between the parentheses is true, the code in the following brackets will execute. If Java determines that the statement is false, the code in the brackets will be completely skipped. Essentially, we're going to give this if statement two pieces of input. We're going to give it the variable input, which if you remember contains the integer value that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access