Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char sign = ' ';
- double a=0, b=0;
- Scanner in = new Scanner(System.in);
- System.out.println("Please enter the number:");
- a = in.nextDouble();
- while(sign != 's')
- {
- System.out.println("Please enter the sign");
- sign = in.next().charAt(0);
- if (sign == '+')
- {
- System.out.println("Please enter the next number:");
- b = in.nextDouble();
- a+=b;
- }
- if (sign == '-')
- {
- System.out.println("Please enter the next number:");
- b = in.nextDouble();
- a-=b;
- }
- if (sign == '*')
- {
- System.out.println("Please enter the next number:");
- b = in.nextDouble();
- a*=b;
- }
- if (sign == '/')
- {
- System.out.println("Please enter the next number:");
- b = in.nextDouble();
- a/=b;
- }
- if (sign == '^')
- {
- System.out.println("Please enter the next number:");
- b = in.nextDouble();
- a = Math.pow(a, b);
- }
- if (sign == 'v')
- {
- a=Math.sqrt(a);
- }
- }
- System.out.print(a);
Add Comment
Please, Sign In to add comment