Guest User

Untitled

a guest
Jan 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. private static String operation;
  2.  
  3. public static void main(String[] args)
  4. {
  5. Scanner in = new Scanner(System.in);
  6. // Ask user how many numbers he/she wants to use
  7. System.out.print("How many numbers are you using? (3 numbers maximum) ");
  8. int numberFirst = in.nextInt();
  9.  
  10. if (numberFirst > 3) {
  11. System.out.println("You can't do that. Please start over.");
  12. System.out.close();
  13. }
  14. if (numberFirst < 2) {
  15. System.out.println("You can't do that. Please start over.");
  16. System.out.close();
  17. }
  18. // Ask user to type in numbers
  19. System.out.println("Enter first number used: ");
  20. double num1 = in.nextDouble();
  21. System.out.println("Enter second number used: ");
  22. double num2 = in.nextDouble();
  23.  
  24. if (numberFirst == 2)
  25. System.out.println("Press '0' and press 'enter.'");
  26.  
  27. if (numberFirst == 3) {
  28. System.out.println("Enter third number used: ");
  29. }
  30. double num3 = in.nextDouble();
  31.  
  32. // Output numbers user entered
  33. if (numberFirst == 2) {
  34. System.out.println("You are using " + num1 + " and " + num2 + ".");
  35. }
  36. if (numberFirst == 3) {
  37. System.out.println("You are using " + num1 + ", " + num2 + ", and " + num3 + ".");
  38. }
  39. // Put a key for the operations
  40. System.out.println("Addition: Enter '1'");
  41. System.out.println("Subtraction: Enter '2'");
  42. System.out.println("Multiplication: Enter '3'");
  43. System.out.println("Division: Enter '4'");
  44. if (numberFirst == 2) {
  45. System.out.println("Exponent: Enter '5'");
  46. }
  47. // Ask user what operation he/she wants
  48. System.out.println("Enter operation: ");
  49. operation = in.next();
  50.  
  51. // Print the operation that user is using AND print the answer (2 numbers)
  52. if (numberFirst == 2) {
  53. if (operation.equals("1"))
  54. System.out.println("You are using addition." + " Your answer is " + (num1 + num2) + ".");
  55. }
  56. if (numberFirst == 2) {
  57. if (operation.equals("2"))
  58. System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2) + ".");
  59. }
  60. if (numberFirst == 2) {
  61. if (operation.equals("3"))
  62. System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2) + ".");
  63. }
  64. if (numberFirst == 2) {
  65. if (operation.equals("4"))
  66. System.out.println("You are using division." + " Your answer is " + (num1 / num2) + ".");
  67. }
  68. if (numberFirst == 2) {
  69. if (operation.equals("5"))
  70. System.out.println("You are using an exponent." + " Your answer is " + Math.pow(num1, num2) + ".");
  71. }
  72.  
  73. // Print the operation that user is using AND print the answer (3 numbers)
  74. if (numberFirst == 3) {
  75. if (operation.equals("1"))
  76. System.out.println("You are using addition." + " Your answer is " + (num1 + num2 + num3) + ".");
  77. }
  78. if (numberFirst == 3) {
  79. if (operation.equals("2"))
  80. System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2 - num3) + ".");
  81. }
  82. if (numberFirst == 3) {
  83. if (operation.equals("3"))
  84. System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2 * num3) + ".");
  85. }
  86. if (numberFirst == 3) {
  87. if (operation.equals("4"))
  88. System.out.println("You are using division." + " Your answer is " + ((num1 / num2) / num3) + ".");
Add Comment
Please, Sign In to add comment