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
- [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…
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
-
-
-
-
-
-
-
(Locked)
What are functions? (conceptually)4m 25s
-
(Locked)
Defining functions in Java3m 28s
-
(Locked)
Calling functions in Java5m 9s
-
(Locked)
Parameters in Java5m 30s
-
(Locked)
Return types in Java5m 34s
-
(Locked)
Using built-in functions in Java4m 43s
-
(Locked)
Challenge: Salary calculator1m 21s
-
(Locked)
Sample solution: Salary calculator3m 46s
-
(Locked)
-
-