Advertisement
jade143

Compiling activities with Nested Switch

Nov 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Activitiesfusionswitch {
  3.  
  4. public static void main(String[] args) {
  5. /* Combining All Activities using Switch method
  6. * RnB Dela Pe�a
  7. */
  8.  
  9. Scanner rnb = new Scanner(System.in);
  10. System.out.print("Choose Number 1-8 for Activities: ");
  11. int activity=rnb.nextInt();
  12.  
  13. switch (activity) {
  14. case 1: System.out.println("\nYou Choose Activity 1 ADD or EVEN Number ");
  15. System.out.print("\nPlease Enter Number: ");
  16. int ae=rnb.nextInt();
  17. if (ae%2 == 0) {
  18. System.out.print(ae+ " is an even number");
  19. }
  20. else
  21. {
  22. System.out.print("This is an ODD number");
  23. }
  24. break;
  25. case 2: System.out.print("You Choose Activity 5 Colors Using Switch");
  26. System.out.print("Choose a letter from R O Y G B I V or r o y g b i v:: ");
  27. String InputColor = rnb.next();
  28.  
  29. switch (InputColor){
  30. case "R": case "r":
  31. System.out.print("The color you have selected is Red");
  32. break;
  33. case "O": case "o":
  34. System.out.print("The color you have selected is Orange");
  35. break;
  36. case "Y": case "y":
  37. System.out.print("The color you have selected is Yellow");
  38. break;
  39. case "G": case "g":
  40. System.out.print("The color you have selected is Green");
  41. break;
  42. case "B": case "b":
  43. System.out.print("The color you have selected is Blue");
  44. break;
  45.  
  46. case "I": case "i":
  47. System.out.print("The color you have selected is Indigo");
  48. break;
  49. case "V": case "v":
  50. System.out.print("The color you have selected is Violet");
  51. break;
  52. case 6:/* */
  53. int Val0 = rnb.nextInt();
  54. System.out.print("Please enter 2nd value: ");
  55. int Val1 = rnb.nextInt();
  56. System.out.print("Please enter 3rd value: ");
  57. int Val2 = rnb.nextInt();
  58.  
  59. if ((Val0 >= Val2) && (Val1>=Val2))
  60. {
  61. System.out.print (Val0+ " is the largest among all values");
  62. }
  63. else if ((Val1>=Val0)&&(Val1>=Val2))
  64. {
  65. System.out.print(Val1+" is the largest among all values");
  66. }
  67. else if ((Val2>=Val0)&&(Val2>=Val1))
  68. {
  69. System.out.print(Val2+" is the largest among all values");
  70. }
  71. case 7:
  72. long val1 = rnb.nextLong();
  73. int digits = 1;
  74.  
  75. if (val1 >=10 && val1<=10)
  76. {
  77. digits = 2;
  78.  
  79. if (val1>=100 && val1<=100)
  80. {
  81. digits = 3;
  82. }
  83. else if (val1 >=1000 && val1 <=1000)
  84. {
  85. digits = 4;
  86. }
  87. System.out.print(val1+ " is a "+digits+" digit number");
  88. }
  89. case 8:
  90. int val1 = rnb.nextInt();
  91. System.out.print("Please enter the OPERATOR to be use: ");
  92. char operators = rnb.next().charAt(0);
  93. System.out.print("Please enter the 2nd value: ");
  94. int val2 = rnb.nextInt();
  95. int total = 0;
  96.  
  97. switch(operators )
  98. {
  99. case '*':
  100. total = val1 * val2;
  101. System.out.print(val1+" "+operators+" "+val2+" = "+total);
  102. break;
  103. case '/':
  104. total = val1 / val2;
  105. System.out.print(val1+" "+operators+" "+val2+" = "+total);
  106. break;
  107. case '+':
  108. total = val1 + val2;
  109. System.out.print(val1+" "+operators+" "+val2+" = "+total);
  110. break;
  111. case '-':
  112. total = val1 - val2;
  113. System.out.print(val1+" "+operators+" "+val2+" = "+total);
  114. break;
  115. case '%':
  116. total = val1 % val2;
  117. System.out.print(val1+" "+operators+" "+val2+" = "+total);
  118. break;
  119. default:
  120. System.out.print("The number you entered is out of the list");
  121. break;
  122. }
  123. }
  124. }
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement