课程: Java Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Code Solution: Calculator

Code Solution: Calculator

(upbeat music) - [Instructor] For this task, your challenge was to implement the add, subtract, and multiply and divide methods of a calculator app. Let's take a look at the calculate numbers method, which accepts two integers, first number and second number, and then performs a series of operations on those numbers and returns a final result. Notice how the value of the initial calculation is stored in a variable called result, and then that result is used in subsequent operations. Also, notice how each operation is scoped to its own method, focusing on a single task. In the add method, let's return the sum of num1 plus num2. In the subtract method, we'll say num1 minus num2. In the multiply method, we'll say num1 times num2. And finally, in the divide method, we'll say, num1 divided by num2, and let's go ahead and test this. Great. We see that it worked.

内容