Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Реализуйте калькулятор, который должен уметь выполнять следующие математические операции над целыми
- * положительными числами: +, -, *, /, ^, %
- * выведите на экран результат работы калькулятора с помощью System.out.println()
- * Код пишем только ВНУТРИ метода main (для каждого класса метод main будет своим)
- */
- public class Calculator {
- public static void main (String [] args) {
- int a = 5;
- int b = 6;
- char sign = '+'; // +, -, *, /, ^, %
- if (sign == '+') {
- int sum = a + b;
- System.out.println(sum);
- }
- else if (sign == '-') {
- int subtraction = a - b; //вычитание
- System.out.println(subtraction);
- }
- else if (sign == '*') {
- int multiplication = a*b;
- System.out.println(multiplication);
- }
- else if (sign == '%') {
- int remainderOfDivision = a%b;
- System.out.println(remainderOfDivision);
- }
- else if (sign == '^') {
- int degree = 1 ;
- for (int i = 0; i == b; i ++ )
- degree = degree*a;
- //double degree = Math.pow(a, b);
- System.out.println(degree);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement