Commit 4a09e17
committed
feat: Add FunctionCC5 class with printSquare method
WHAT the code does:
- Defines a `FunctionCC5` class with a static method `printSquare(int num)`.
- `printSquare()` computes the square of the input number and prints the result.
- `main()` calls `printSquare(5)` as a demonstration.
WHY this matters:
- Demonstrates **user-defined methods** in Java.
- Reinforces arithmetic operations and method parameter passing.
- Shows how to separate computation logic into reusable methods.
HOW it works:
1. `printSquare(5)` → computes `5 * 5 = 25`.
2. Prints → `"Square of 5 is: 25"`.
Tips & gotchas:
- Currently prints result only; could be extended to return the value for reuse.
- Works only for integers; using `long` or `BigInteger` avoids overflow for large inputs.
- Negative inputs are valid (e.g., `-3` → `9`).
- Method name `printSquare` is descriptive, aligning with best practices.
Use-cases:
- Educational example for methods with parameters.
- Utility method for math-related applications.
- Starter function to extend into more math operations (cube, power, etc.).
- Interview prep for **basic function implementation**.
Short key: class-function cc5-print square.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent b48f970 commit 4a09e17
1 file changed
+14
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 1 | + | |
| 2 | + | |
12 | 3 | | |
13 | 4 | | |
14 | 5 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 6 | + | |
| 7 | + | |
18 | 8 | | |
19 | 9 | | |
20 | 10 | | |
21 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments