Commit 4e9b93c
committed
feat: Add MethodsCC class with squareAndCube method
WHAT the code does:
- Defines a `MethodsCC` class with a static method `squareAndCube(int x)`.
- `squareAndCube()` prints the square and cube of the input integer.
- `main()` calls this method for values `2`, `3`, and `4`.
WHY this matters:
- Demonstrates **methods with parameters** for reusable logic.
- Reinforces arithmetic operations and function abstraction.
- Shows how the same method can be reused for multiple inputs.
HOW it works:
1. `squareAndCube(2)` → prints `4` and `8`.
2. `squareAndCube(3)` → prints `9` and `27`.
3. `squareAndCube(4)` → prints `16` and `64`.
Tips & gotchas:
- Current implementation prints directly — could be enhanced to return results for reuse.
- Works fine for small integers; for large values, consider `long` or `BigInteger` to avoid overflow.
- Method naming (`squareAndCube`) is descriptive and follows good practice.
Use-cases:
- Educational demo for **methods with arguments**.
- Useful in teaching function reusability in math-related problems.
- Can be extended into a math utility library.
- Good exercise for beginners in Java.
Short key: class-methodscc-square-cube.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent c4c50b5 commit 4e9b93c
1 file changed
+22
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | | - | |
9 | | - | |
| 6 | + | |
10 | 7 | | |
11 | 8 | | |
12 | 9 | | |
| |||
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
| 19 | + | |
| 20 | + | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| 27 | + | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | | - | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | | - | |
| 45 | + | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
44 | 48 | | |
45 | | - | |
46 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments