0% found this document useful (0 votes)
10 views4 pages

9.1 Java - Lecture31 PDF

This lesson explains the use of the return keyword in methods to send output back to the caller. An example is provided where the add method returns the sum of two integers, which is then printed in the main method. The lesson concludes with a note about upcoming homework related to applications with decisions and loops.

Uploaded by

oanodocometa1997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

9.1 Java - Lecture31 PDF

This lesson explains the use of the return keyword in methods to send output back to the caller. An example is provided where the add method returns the sum of two integers, which is then printed in the main method. The lesson concludes with a note about upcoming homework related to applications with decisions and loops.

Uploaded by

oanodocometa1997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lesson 31

Transfer of Control
Statements 2 (return).

PRESENTED BY

Keith Vassallo [Link]


return
- The return keyword is used to send the output of a method back to the
caller of the method.
- We will cover this in detail later on, however:
public class SomeClass {
- The result of num1+num2 will be
int add(int num1, int num2) { an int, so the return type of the
return num1+num2; add method is set to int.
}
- After the addition is done, the
public static void main(String[] args) {
result is sent back to
SomeClass sc = new SomeClass(); the line that called it (in the main
method in this case).

[Link]
int result = [Link](4,17);
[Link](result); - We store the result and
}
display it to the user.
}
Great work, you’ve completed this lesson!

Next up: Homework 4: An Application


with Decisions and Loops.

[Link]
© 2011-2017 Institute of Computer Education Ltd.

The contents of this document are copyright to the Institute of Computer Education Ltd, unless otherwise stated, and must not be reproduced without permission.

Every effort has been made to trace all of the copyright holders, but if any have been inadvertently overlooked the Institute of Computer Education Ltd. will be pleased to make the necessary arrangements at the first
opportunity. Please contact us directly. While the Institute of Computer Education Ltd. has taken all reasonable care in the preparation of this work, the Institute of Computer Education Ltd. makes no representation,
express or implied, with regard to the accuracy of the information contained in this work and cannot accept any legal responsibility or liability for any errors or omissions from the work or the consequences thereof.
The reader assumes sole responsibility for the selection of these materials to achieve its intended results. Products and services that are referred to in this work may be either trademarks and/or registered
trademarks of their respective owners. The editors and author/s make no claim to these trademarks. [Link]

You might also like