public class Solution {
public static void main(String[] args) {
//write your code here
int a=sqr(5);
System.out.println(a);
}
public static int sqr(int a) {
return a * a;
}
}
Please explain the return statement
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
MichelMk
12 October 2020, 19:24useful
Hi Dinesh,
As far as I know, everything that is written behind the return statement is "returned" as an output of the method in which it is used. So e.g. in your problem above, the sqr() method is a function that returns an in (because the method is defined as public static int sqr(int a) { } ). The bold int here, means that the output of sqr() should be an int.
Now in your function you wrote "return a * a;". Which means that the output of the sqr() method will be an integer with the value "a * a"
Does this help a bit? 😀
+1