Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. package steppingstone3_branches;
  2. import java.util.Scanner;
  3. /**
  4. *
  5. * @author kassn
  6. */
  7. public class SteppingStone3_Branches {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12. public static void main(String[] args) {
  13. int numberCups = -1;
  14.  
  15. Scanner scnr = new Scanner(System.in);
  16.  
  17. System.out.println("Please enter the number of cups (between 1 and 100): ");
  18.  
  19. //The following "if branch" uses the scanner method hasNextInt() to
  20. //check to see if the input is an int.
  21. if (scnr.hasNextInt()) {
  22. numberCups = scnr.nextInt();//user enters number of cups of ingredient
  23. }
  24. if (numberCups > 0 && numberCups < 101){//if user entered number of cups is greater than 0 and less than 101
  25. System.out.println(numberCups + " is a valid number of cups!");//will print user entered number is a valid number of cups!
  26. }
  27. if (numberCups >= 101) {//if number of cups entered by user is greater than or equal to 101
  28. System.out.print(numberCups + " is not a valid number of cups!");//System.out.println(numberCups + " is a valid number of cups!");
  29. 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.
  30. } else if (numberCups < 1){//if number of cups entered by user is less than 1
  31. 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!
  32. 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.
  33. }
  34. numberCups = scnr.nextInt();{ //prompt user to enter the number of cups for the ingredient again.
  35.  
  36. if (numberCups >= 101){//if number of cups entered by user is greater than or equal to 101
  37. 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
  38. 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.
  39. }
  40. else if (numberCups < 1){//if number of cups entered by user is less than l
  41. 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.
  42. }
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement