From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Creating a simple calculator application

Solution: Creating a simple calculator application - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Solution: Creating a simple calculator application

- So here's my solution to the challenge to create a simple calculator application that receives two numbers from the user, adds them together, and reports the result. I'm opening the project SimpleCalc. In my main method, I've created a scanner object. Notice that I have an import statement on line three. The scanner class is a member of java.util, and so it must be imported to be used. At line 11 I'm outputting a prompt, "Enter a numeric value", and then I'm collecting the data from the user, calling the scanner object nextLine method. Then I'm parsing that string as a double value. Notice that right now I don't have any error handling in this code. I'll be talking about error handling in just a little while, but for now we're trusting that the user will type in a numeric value. I'm repeating that process to get the second number, then I'm adding the two values together and displaying the results using system.out again. So that's my solution to the challenge. Take a look at your…

Contents