-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepositoryFile2.1
More file actions
30 lines (25 loc) · 882 Bytes
/
RepositoryFile2.1
File metadata and controls
30 lines (25 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// File: H2Utility.java
import java.sql.SQLException;
public class H2Utility {
// Add two numbers
public static int add(int a, int b) {
return a + b;
}
// Greet the user
public static String greet(String name) {
return "Hello, " + name + "!";
}
// Division with exception handling
public static double safeDivide(int numerator, int denominator) throws SQLException {
if (denominator == 0) {
throw new SQLException("Cannot divide by zero");
}
return (double) numerator / denominator;
}
// Combine all: compute (a + b) / c and greet the user
public static String computeAndGreet(String name, int a, int b, int c) throws SQLException {
int sum = add(a, b);
double result = safeDivide(sum, c);
return greet(name) + " The computed result is: " + result;
}
}