-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayFunHouse.java
executable file
·112 lines (98 loc) · 2.08 KB
/
ArrayFunHouse.java
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
Miles Robertson
11-7-16
Per 6
Inroduction to Arrays
*/
import java.lang.System;
import java.lang.Math;
public class ArrayFunHouse
{
//instance variables and constructors could be used, but are not really needed
//getSum() will return the sum of the numbers from start to stop, not including stop
public static int getSum(int[] numArray, int start, int stop)
{
int x=0;
int begin=start;
int end=stop;
while(begin <= end)
{
x = x + numArray[begin];
begin = begin + 1;
}
return x;
}
//getCount() will return number of times val is present
public static int getCount(int[] numArray, int val)
{
int valu = val;
int y=0;
int n=0;
while(y<numArray.length)
{
if (numArray[y] == valu)
{
n = n+1;
}
y = y+1;
}
return n;
}
public static int[] removeVal(int[] numArray, int val)
{
int [] result = new int [numArray.length-getCount(numArray, val)];
for (int i= 0; i < result.length; i++)
{
if(numArray[i] != val)
{
result[i] = numArray[i];
}
}
/*
int valu = val;
int y=0;
int n=0;
int m=0;
int thirdcup =0;
while(y<numArray.length)
{
if (numArray[y] != valu)
{
m = m+1;
}
/*
else
{
}
*/
/*
y = y+1;
}
/*
int[] without = new int[m];
System.out.println(m);
int [] remove = new int[m];
while(n<m)
{
if (numArray[n] != valu)
{
thirdcup = numArray[n];
remove[n] = thirdcup;
}
/*
else
{
}
*/
/*
n=n+1;
}
*/
return result;
//how can i make it not print the jibberish?
//System.out.println(Arrays.toString(remove));
}
/*public static int[] print()//supposed to be a new method
{
}*/
}