forked from CMPSC-1500/LAB-3
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLab3JaredP.java
More file actions
88 lines (63 loc) · 1.77 KB
/
Lab3JaredP.java
File metadata and controls
88 lines (63 loc) · 1.77 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
80
81
public class Lab3JP {
public static void main(String[] args)
{
System.out.println((5*6) + " : " + multiplication(5,6));
System.out.println(((5 + 4) - 12) + " : " + subtract(add(5, 4), 12));
System.out.println((80/10) + " : " + divide(80,10));
System.out.println(modulo(20,8));
System.out.println("dog + house =" + " : " + concatination("dog","house"));
System.out.println(repeat("shark", 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 multiplication(int x, int y) {
int result = 0;
for(int i = 0; i < y; i++){
result= add(result,x);
}
return result;
}
private static int divide(int x, int y)
{
int result = x;
int divide = 0;
while (result > 0) {
result = result - y;
divide = divide + 1;
}
return divide;
}
private static int modulo(int x, int y)
{
int result = x;
while (result > y) {
result = result - y;
}
return result;
}
private static String concatination(String first, String last)
{
return first+last;
}
private static String repeat(String string, int n)
{ String current= string;
for(int i=1; i < n; i++) {
current += string;
}
return current;
}
}