_MuradPro_

Calculator

Dec 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. char sign = ' ';
  2.         double a=0, b=0;
  3.         Scanner in = new Scanner(System.in);
  4.         System.out.println("Please enter the number:");
  5.         a = in.nextDouble();
  6.         while(sign != 's')
  7.         {
  8.             System.out.println("Please enter the sign");
  9.             sign = in.next().charAt(0);
  10.             if (sign == '+')
  11.             {
  12.                 System.out.println("Please enter the next number:");
  13.                 b = in.nextDouble();
  14.                 a+=b;
  15.             }
  16.             if (sign == '-')
  17.             {
  18.                 System.out.println("Please enter the next number:");
  19.                 b = in.nextDouble();
  20.                 a-=b;
  21.             }
  22.             if (sign == '*')
  23.             {
  24.                 System.out.println("Please enter the next number:");
  25.                 b = in.nextDouble();
  26.                 a*=b;
  27.             }
  28.             if (sign == '/')
  29.             {
  30.                 System.out.println("Please enter the next number:");
  31.                 b = in.nextDouble();
  32.                 a/=b;
  33.             }
  34.             if (sign == '^')
  35.             {
  36.                 System.out.println("Please enter the next number:");
  37.                 b = in.nextDouble();
  38.                 a = Math.pow(a, b);
  39.             }
  40.             if (sign == 'v')
  41.             {
  42.                 a=Math.sqrt(a);
  43.             }
  44.            
  45.         }
  46.         System.out.print(a);
Add Comment
Please, Sign In to add comment