forked from CMPSC-1500/LAB-3
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJacksonMaschman.java
More file actions
76 lines (60 loc) · 1.3 KB
/
JacksonMaschman.java
File metadata and controls
76 lines (60 loc) · 1.3 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
public class Practice3
{
public static void main(String[] args)
{
System.out.println(modulo(14, 3));
}
private static int add(int x, int y)
{
int result = 0;
for(int i = 0; i < x; i = i + 1)
result = result + 1;
for(int i = 1; i <= y; i= i + 1)
result = result + 1;
return result;
}
private static int subtract(int x, int y)
{
int result = add(x,0);
for(int i = 0; i < y; i = i + 1)
result = result - 1;
return result;
}
private static int multiply(int x, int y)
{
int result = 0;
for(int i = 0; i < x; i = i + 1)
{
result = result + y;
}
return result;
}
private static int divide(int x, int y)
{
int counter = 0;
while (x > 0)
{
x = x - y;
counter = counter + 1;
}
return counter;
}
private static int modulo(int x, int y)
{
int i = divide(x, y);
int counter = 0;
if(i != (x/y))
{
while(i != 0)
{
i = i - 1;
counter = counter + 1;
}
return counter;
}
else
{
return 0;
}
}
}