Commit bf0c63a
committed
feat: Add FunctionsCC3 class with calculateSum using user input
WHAT the code does:
- Defines a `FunctionsCC3` class with a static method `calculateSum(int num1, int num2)` that returns the sum of two numbers.
- Uses `Scanner` to read two integers from the user.
- Calls `calculateSum()` with the input values and prints the result in a formatted message.
WHY this matters:
- Demonstrates combining **user input handling** with method calls.
- Shows how to pass values dynamically to methods instead of hardcoding.
- Reinforces the distinction between returning results vs printing inside the method.
HOW it works:
1. Program prompts for `"Enter first number:"` and `"Enter second number:"`.
2. Reads values `a` and `b` via `Scanner`.
3. Passes them into `calculateSum(a, b)` → computes and returns sum.
4. Prints result in format: `"Sum = X"`.
Tips & gotchas:
- `Scanner` should be closed after use (`sc.close()`).
- Input validation (e.g., handling non-integer input) is not included.
- Works only for integers — could be extended to handle doubles.
- For larger numbers, `long` may be safer to prevent overflow.
Use-cases:
- Educational example for **method with return value + user input**.
- Foundation for calculator-style programs.
- Can be extended with additional operations (subtract, multiply, divide).
- Useful for practicing console-based interactive applications.
Short key: class-functions cc3-calculate sum-user input.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 9b13f8e commit bf0c63a
1 file changed
+12
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
| 7 | + | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
10 | 17 | | |
11 | | - | |
| 18 | + | |
0 commit comments