forked from CMPSC-1500/LAB-3
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathelijahbeed_Lab3.java
More file actions
79 lines (61 loc) · 1.69 KB
/
elijahbeed_Lab3.java
File metadata and controls
79 lines (61 loc) · 1.69 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
77
78
79
public class math {
public static void main(String[] args)
{
System.out.println( ((5+4)-12) + " : " + subtract(add(5,4),12) );
System.out.println( divide(27,3) + " : " + multiply(5, 3) );
System.out.println( modulo(27,10) + " : " + concat("cat","dog"));
System.out.println( stringRepeat("cat",5));
}
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 v, int w)
{
int result = 0;
for(int i=0; i < w; i = i + 1)
result = result + v;
return result;
}
private static int divide(int v, int w)
{
int result = v;
int numberDivide = 0;
while (result > 0) {
result = result - w;
numberDivide = numberDivide + 1;
}
return numberDivide;
}
private static int modulo(int v, int w)
{
int result = v;
while (result > w) {
result = result - w;
}
return result;
}
private static String concat(String first, String last)
{
return first+last;
}
private static String stringRepeat(String string, int n)
{
String totalRepeat = "";
for(int i=0; i < n; i = i + 1)
totalRepeat = totalRepeat + string;
return totalRepeat;
}
}