From the course: Java 11+ Essential Training

Unlock the full course today

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

Solution: A simple calculator

Solution: A simple calculator - Java Tutorial

From the course: Java 11+ Essential Training

Start my 1-month free trial

Solution: A simple calculator

(upbeat electronic music) - [Instructor] In the previous video, I issued a challenge, create a very simple calculator application that can receive two values with fractions, and then divide one number by the other. I'll show you the code that I created to accomplish this. As in a previous video, I created an instance of the scanner class that collects information from system.in. This is something called an input stream and it's data provided by the user in a console application. I used system.out.print without the print line to display prompts, and then after each prompt I received some data. Instead of using next line or next int as I did previously, I used the next double method, and that allows me to receive a numeric value that has a fraction. I received two variables that I named d1 and d2, you could name them anything you want, and then I divided one number by the next. And then I displayed the result. Now…

Contents