← Unit 3 · all exercises
Saved in this browser only

A helper that needs no object

Write a MathHelper class with a static method square that returns a number multiplied by itself, and a static method cube that returns it multiplied by itself twice. Neither needs an object to be called.

class MathHelper { static int square(int n); static int cube(int n); }

MathHelper.java
Loading editor…
Results

Examples

  • MathHelper.square(4) → 16
  • MathHelper.cube(3) → 27

There are also 4 hidden tests you can't see. Solve the problem, not the examples.