-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdivision.java
More file actions
46 lines (43 loc) · 1.25 KB
/
division.java
File metadata and controls
46 lines (43 loc) · 1.25 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class division {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.print("take the value of b (divident) = ");
int b = scn.nextInt();
System.out.print("take the value of a (divisor) = ");
int a = scn.nextInt();
divide(a, b);
scn.close();
}
public static int count(int digit) {
int temp = 0;
while (digit > 0) {
digit = digit / 10;
temp++;
}
return temp;
}
public static void divide(int a, int b) {
if (a != 0) {
int quotient = 0;
int temp = 10 * a;
int Bdigit = count(b);
while (Bdigit > count(a)) {
if (temp < b) {
b = b - temp;
quotient += 10;
} else {
Bdigit--;
}
}
while (b >= a) {
quotient++;
b = b - a;
}
int remainder = b;
System.out.println(" Quotient is " + quotient + " and Remainder is " + remainder);
} else {
System.out.println("dividing by zero is undermined");
}
}
}