task01.task0127 - Square of a number
pleas explain this task.
need explanation
Archived
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Jeff Jeffy
19 March 2019, 02:05
Hi. Next time, attach a code with the option, it makes it easier to those responding to get at what you mean.
Anyhow, to get on with it, sqr is already made for you. What you need to do is wrap it like this: System.out.println(sqr(5));
What that's doing is:
(1) Sending sqr the number 5 to take the place of a.
(2) Having sqr return a*a, which, in this case, is 5*5, meaning it would subsitute sqr(5) with 25
(3) Printing out the value of sqr(5), which is 25
+1
Lex Medeiros
18 March 2019, 21:33
Square of a number means that you have to multiply the number by itself once.
So you need to write a method that "calls" the method sqr that is already written in the exercise.
Here is the method sqr:
public static int sqr(int a) {
return a * a;
}
So you need to add to the main method a function to writes out the result: System.out.println(); and include the square method call with number 5 to output.
0
Renat Mukhametshin
18 March 2019, 11:59
ok, you need:
In the main method call the sqr method with 5 as an argument, and result it pass to the print command
(I'am from russia, so my english may be is not good)
0
Teclaire bahel
18 March 2019, 03:26
return the square of the number.
0