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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Working with object data types6m 27s
-
Using the String class5m 5s
-
Converting primitive values to strings4m 15s
-
Building a string from multiple values8m 44s
-
Comparing string values5m 51s
-
Formatting numeric values as strings4m 41s
-
Parsing string values3m 13s
-
Working with dates and times8m 35s
-
Challenge: Creating a simple calculator application1m 28s
-
Solution: Creating a simple calculator application1m 19s
-
-
-
-
-
-
-
-
-