forked from CMPSC1500-Spring17/LAB-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods_Practice.txt
More file actions
52 lines (40 loc) · 1.15 KB
/
Methods_Practice.txt
File metadata and controls
52 lines (40 loc) · 1.15 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
public class Method_Practice {
public static void main(String[] args)
{
System.out.println( "the answer is " + Divide(39, 4) );
}
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 a, int b)
{
int result = 0;
for( int i = 0; i < a; i++ )
result = result + b;
return result;
}
private static int Divide(float c, float d)
{
float dividend = c;
int result = 0;
while (dividend >= d)
{
dividend = dividend - d;
result = result + 1;
}
return result;
}
}