October 2017
Beginner
318 pages
7h 26m
English
It turns out that there's a slightly easier way to write the preceding program. When we write a conditional statement or rather a pair of conditional statements in which we're always going to execute one of the two code blocks, it's probably a good time to make use of the else keyword. The else keyword must follow a bracketed if block, then it's followed by brackets of its own. The else statement will evaluate to true and execute the code between its brackets only if the code between the previous if brackets was not executed:
import java.util.*; public class ConditionalStatements { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.println("Input now: "); int input = reader.nextInt(); ...Read now
Unlock full access