2.3 Calling and returning in a method

To return in a method, return as you would in the main method.
int hello(){ return 0; }
As for parameters, you may initialize them in three ways.
int hello (parameters); int goodbye (int good, int bye); int howAreYou (int, int);
If you want to save the value of what a function returns, store it into a variable.

Mini Project

Create a method, outside of the main method, that adds an “ !“ to a given char array (char[]). Remember the space!
Input: Hello
Output: Hello !

Previous Section

Next Section

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.