Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package steppingstone3_branches;
- import java.util.Scanner;
- /**
- *
- * @author kassn
- */
- public class SteppingStone3_Branches {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int numberCups = -1;
- Scanner scnr = new Scanner(System.in);
- System.out.println("Please enter the number of cups (between 1 and 100): ");
- //The following "if branch" uses the scanner method hasNextInt() to
- //check to see if the input is an int.
- if (scnr.hasNextInt()) {
- numberCups = scnr.nextInt();//user enters number of cups of ingredient
- }
- if (numberCups > 0 && numberCups < 101){//if user entered number of cups is greater than 0 and less than 101
- System.out.println(numberCups + " is a valid number of cups!");//will print user entered number is a valid number of cups!
- }
- if (numberCups >= 101) {//if number of cups entered by user is greater than or equal to 101
- System.out.print(numberCups + " is not a valid number of cups!");//System.out.println(numberCups + " is a valid number of cups!");
- System.out.print("Please enter another number of cups between 1 and 100:");//will ask user to enter number of cups again between 1 and 100.
- } else if (numberCups < 1){//if number of cups entered by user is less than 1
- System.out.println(numberCups + " is not a valid number of cups!"); //will print number of cups entered by user is not a valid number of cups!
- System.out.println("Please enter another number of cups between 1 and 100:");//will ask user to enter number of cups again between 1 and 100.
- }
- numberCups = scnr.nextInt();{ //prompt user to enter the number of cups for the ingredient again.
- if (numberCups >= 101){//if number of cups entered by user is greater than or equal to 101
- System.out.println(numberCups + " is not a valid number of cups!");//will print user entered number of cups is not a valid number of cups
- System.out.println(numberCups + " is greater than 100. Sorry you are out of attempts.");//will print useer entered number of cups is greater than 100. Sorry you are out of attempts.
- }
- else if (numberCups < 1){//if number of cups entered by user is less than l
- System.out.println(numberCups + " is less than 1. Sorry you are out of attempts.");//will printer user entered number of cups is less than 1. Sorry you are out of attempts.
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement