From the course: Learning Java 11

Unlock the full course today

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

Return types in Java

Return types in Java - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Return types in Java

- [Instructor] So far, the only way we've outputted data is System.out.println, and this really outputs data to the user. We've gathered input from the user in the past with the scanner, and in the last lesson, we learned how to input data into functions using parameters. Now we're going to learn how to output data from functions using return types. We'll talk more about return types in a second, but imagine you go to a restaurant with four of your friends, and you all order similarly priced meals and want to tip and tax the same amount. The listed meal price comes out to be $100. You want to tip 20%, or .20, as a group, and the sales tax is .08, 8%. With the function you created in the last video, we can calculate the total meal cost, which will come out to 128, and that would get printed out to the console. Now what if we wanted to split the bill among me and my friends? The total meal cost is 128, but I want to know what each person owes on the bill. We could add a parameter to our…

Contents