From the course: Learning Java 11
Unlock the full course today
Join today to access over 23,200 courses taught by industry experts.
Decision-making with if in Java - Java Tutorial
From the course: Learning Java 11
Decision-making with if in Java
- [Instructor] Let's review our Fortune Teller program. There are three main parts to this program. First, we ask the user to pick a number between one and 10. Next, we output the user's fortune depending on which number is inputted. Let's implement this program. In the code, we already have a print statement that asks the user to pick a number between one and 10. We also have a scanner that reads in the next int a user inputs with the nextInt operation. We save the output in a variable called inputtedNum. Now, we have to make a decision in our program. If the inputtedNum is less than five, the program should output the good luck fortune. If the inputtedNum is equal to or greater than five, the program should print out the shoe selection fortune. Before, we were just using blocks but this is a specific type of control flow statement that starts with an if so we call it an if statement. An if statement is a control flow…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.