Você está na página 1de 3

Java Code: 1 import java.util.

*; 2 public class Calculator 3 { 4 public static void main(String[] args) { 5 /*Scanner input = new Scanner(System.in); 6 System.out.println("What are you doing?"); 7 if (answer.equalsIgnorecase("multiplication")) 8 { Multiplication(); 9 }*/ 10 System.out.println("Hello, If you are doing Multiplication Type 11 1."); 12 System.out.println("If you are doing Addition, Type 2."); 13 System.out.println("If you are doing Subtraction, Type 3"); System.out.println("If you are doing Division, Type 4"); 14 Scanner input = new Scanner(System.in); 15 int decision; 16 decision = input.nextInt(); 17 if (decision == 1) 18 { Multiplication(); 19 } 20 if (decision == 2) 21 { 22 Addition(); } 23 if (decision == 3) 24 { 25 Subtraction(); 26 } 27 if (decision == 4) { 28 Division(); 29 } 30 else { 31 System.out.println("Those aren't valid numbers."); wrongInput(); 32 } 33 } 34 35 public static void wrongInput() 36 { 37 System.out.println("If you are doing Multiplication Type 1."); System.out.println("If you are doing Addition, Type 2."); 38 System.out.println("If you are doing Subtraction, Type 39 3"); 40 System.out.println("If you are doing Division, Type 4"); 41 Scanner input = new Scanner(System.in); int decision; 42 decision = input.nextInt(); 43 if (decision == 1) 44 { 45 Multiplication();

} 46 if (decision == 2) 47 { 48 Addition(); 49 } if (decision == 3) 50 { 51 Subtraction(); 52 } 53 if (decision == 4) 54 { Division(); 55 } 56 else { 57 System.out.println("Those aren't valid numbers."); 58 wrongInput(); } 59 } 60 public static void Multiplication() 61 { 62 int mInput1; 63 int mInput2; 64 Scanner input = new Scanner(System.in); 65 System.out.print("What is the first number? "); 66 mInput1 = input.nextInt(); 67 68 System.out.print("What is the second number? "); 69 mInput2 = input.nextInt(); 70 71 System.out.println(mInput1 + " times " + mInput2 + " equals " + mInput1 * mInput2); 72 } 73 public static void Addition() 74 { 75 int aInput1; int aInput2; 76 int aAnswer; 77 78 Scanner input = new Scanner(System.in); 79 System.out.println("What is the first number?"); 80 aInput1 = input.nextInt(); 81 82 System.out.println("What is the second number?"); aInput2 = input.nextInt(); 83 84 aAnswer = aInput1 + aInput2; 85 System.out.println(aInput1 + " plus " + aInput2 + " equals " + 86 aAnswer); 87 } public static void Subtraction() 88 { 89 int sInput1; 90 int sInput2; 91 int sAnswer;

92 Scanner input = new Scanner(System.in); 93 System.out.println("What is the first number?"); 94 sInput1 = input.nextInt(); 95 96 System.out.println("What is the second number?"); 97 sInput2 = input.nextInt(); 98 sAnswer = sInput1 - sInput2; 99 System.out.println(sInput1 + " minus " + sInput2 + " equals " + 100 sAnswer); 101 } 102 public static void Division() 103 { int dInput1; 104 int dInput2; 105 int dAnswer; 106 107 Scanner input = new Scanner(System.in); 108 System.out.println("What is the first number?"); dInput1 = input.nextInt(); 109 110 System.out.println("What is the second number?"); 111 dInput2 = input.nextInt(); 112 113 dAnswer = dInput2 / dInput1; 114 System.out.println(dInput1 + " divided by " + dInput2 + " equals " 115+ dAnswer); } 116 117} 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

Você também pode gostar