-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivision.java
More file actions
30 lines (23 loc) · 843 Bytes
/
Copy pathDivision.java
File metadata and controls
30 lines (23 loc) · 843 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
package BasicCalculations;
import java.util.Scanner;
public class Division {
public void execute() {
Scanner sc = new Scanner(System.in);
System.out.println("\n--- Division Operation ---");
System.out.print("Please enter the first number: ");
int num1 = sc.nextInt();
System.out.print("Please enter the second number: ");
int num2 = sc.nextInt();
double result = divide(num1, num2);
System.out.println("\n--- Result ---");
System.out.println("The division of " + num1 + " and " + num2 + " is: " + result);
System.out.println("------------------");
}
public double divide(int a, int b) {
if (b == 0) {
System.out.println("Error: Cannot divide by zero!");
return 0;
}
return (double) a / b;
}
}