Challenge: Simple Calculator
Завдання
Swipe to start coding
Create a method that performs a basic calculation based on the given operation. The method should accept two integers and a string that specifies the operation to perform.
- If the operation is
"add", return the sum of the two numbers. - If the operation is
"subtract", return the difference of the two numbers. - If the operation is
"multiply", return the product of the two numbers. - If the operation is
"divide", return the integer division result of the two numbers. If the second number is zero, throw anArgumentExceptionwith the message"Cannot divide by zero.". - If the operation is not one of the specified options, throw an
ArgumentExceptionwith the message"Invalid operation.".
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 4
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Чудово!
Completion показник покращився до 8.33
Challenge: Simple Calculator
Свайпніть щоб показати меню
Завдання
Swipe to start coding
Create a method that performs a basic calculation based on the given operation. The method should accept two integers and a string that specifies the operation to perform.
- If the operation is
"add", return the sum of the two numbers. - If the operation is
"subtract", return the difference of the two numbers. - If the operation is
"multiply", return the product of the two numbers. - If the operation is
"divide", return the integer division result of the two numbers. If the second number is zero, throw anArgumentExceptionwith the message"Cannot divide by zero.". - If the operation is not one of the specified options, throw an
ArgumentExceptionwith the message"Invalid operation.".
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 4
single