|
| 1 | +// https://www.facebook.com/anushka.saine.735/posts/137136021429328 |
| 2 | +// subscribed by status gram |
| 3 | +import java.util. |
| 4 | + |
| 5 | +//Simple calculator |
| 6 | + |
| 7 | +public class calc |
| 8 | +{ |
| 9 | + public static void main(String[] args) |
| 10 | + { |
| 11 | + Scanner in = new Scanner(System.in); |
| 12 | + double a, b, c = 0.0; |
| 13 | + |
| 14 | + System.out.print("Enter the first number \n"); |
| 15 | + a = in.nextDouble(); |
| 16 | + System.out.print("And enter second \n"); |
| 17 | + b = in.nextDouble(); |
| 18 | + System.out.print("Choose the operation " + |
| 19 | + "\n1.Addition" + |
| 20 | + "\n2.Subtraction" + |
| 21 | + "\n3.Multiplication" + |
| 22 | + "\n4.Division" + |
| 23 | + "\n5.Power" + |
| 24 | + "\n#Please enter the number of operation \n"); |
| 25 | + double somethin = in.nextDouble(); |
| 26 | + double addition = 1; |
| 27 | + double subtraction = 2; |
| 28 | + double multiplication = 3; |
| 29 | + double division = 4 ; |
| 30 | + double power = 5; |
| 31 | + if (somethin == addition) { |
| 32 | + c = a + b; |
| 33 | + System.out.println(a + " + " + b + " = " + c); } |
| 34 | + else if (somethin == subtraction) { |
| 35 | + c = a - b; |
| 36 | + System.out.println(a + " - " + b + " = " + c); } |
| 37 | + else if (somethin == multiplication) { |
| 38 | + c = a * b; |
| 39 | + System.out.println(a + " * " + b + " = " + c); } |
| 40 | + else if (somethin == division) { |
| 41 | + c = a / b; |
| 42 | + System.out.println(a + " / " + b + " = " + c); } |
| 43 | + else if (somethin == power) { |
| 44 | + System.out.println("Enhance A or B?" + |
| 45 | + "\n1.A" + |
| 46 | + "\n2.B"); |
| 47 | + double enhance = in.nextDouble(); |
| 48 | + double first = 1; |
| 49 | + double second = 2; |
| 50 | + if (enhance == first) { |
| 51 | + System.out.println(Math.pow(a, 2)); } |
| 52 | + else if (enhance == second); { |
| 53 | + System.out.println(Math.pow(b, 2)); } |
| 54 | + |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments