Day 1 of daily coding: Functions is java
dev.to·20h·
Discuss: DEV
Flag this post

We know that functions in java are block of code written to perform a specific task. For example if we need to add two numbers multiple times in same code, it would be very tedious to rewrite the same code again and again, so instead we create a function or a method (a function inside a class is called method) in java. So that instead of writing the whole code we can just call that function.

The syntax of a function appears as follow:

<Access specifier>   <returntype>   <name of finction> (parameter){
...body of function
}

Example:

Above is code for function that would print Hello World three times, we can see that at first we mentioned the access specifier then the type of function, as I wrote it in the main class that would contain the main function later in the code, …

Similar Posts

Loading similar posts...