uuijiij
Until this question, the course never teach about passing the parameter. Can someone help?
Archived
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
ThomasLC
18 May 2019, 10:20solution
Passing a parameter to an argument:
"sqr()" is a method.
So in your main method, you can invoke this method anytime by doing sqr()
But if you realize the sqr() method has an arguement called int a:
public static int sqr(int a) {
return a * a;
}
This means you have to pass an argument, in this case, an integer (any number), to the method for it to run.
i.e. sqr(5);
Then the method will take into effect.
For instance, I can now declare a new integer that uses this method:
int newInteger = sqr(5);
Your "newInteger" value would now be 25
+4