forked from CMPSC-1500/LAB-3
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaddyvinton_Lab3.java
More file actions
91 lines (61 loc) · 2.05 KB
/
addyvinton_Lab3.java
File metadata and controls
91 lines (61 loc) · 2.05 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
82
83
84
85
86
87
88
89
90
91
public class LabThree {
public static void main(String[] args)
{
System.out.println( 5+4 + " : " + add(5,4));
System.out.println( ((5+4)-12) + " : " + subtract(add(5,4),12) );
System.out.println( 5*4 + " : " + multiply(5,4));
System.out.println( 20/4 + " : " + divide(20,4));
System.out.println( 5 % 4 + " : " + modulo(5,4));
System.out.println( "blue" + "shoes" + " : " + concatenate("blue","shoes"));
System.out.println("blue" + " : " + repeating("blue", 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 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 result = 0;
for ( int i = x; i >= y; i = i -y)
result = result + 1;
return result;
}
private static int modulo(int x, int y)
{
int result = x;
result = result - multiply(divide(x, y), y);
return result;
}
private static String concatenate(String x, String y)
{
String result = x;
result = x + y;
return result;
}
private static String repeating(String x, int y)
{
String result = x;
for (int i = 1; i<y; i = i + 1)
result = x + " " + result;
return result;
}
}