Commit 4b4a9ef2 authored by daniel.parker's avatar daniel.parker

Second

parent 60c70f61
File added
......@@ -69,6 +69,8 @@ public class Program {
String[] input = {"010","110","111","1010101"};
String[] input2 = {"50","110","FA","B0","F"};
int[] set = {3,6,7,9,8,7,7,6,5,15};
System.out.println(Median(set));
System.out.println(ConvertSingb3ToInt("12"));
System.out.println(ConvertSingb20ToInt("50"));
System.out.println(ConvertSingleHexToInt("50"));
......@@ -387,16 +389,37 @@ public static int Range (int[] input) {
public static int Mode (int[] input) {
int output = 0;
int returnValue = input[0];
int repeatCounter = 0;
int repeater = 0;
return output;
for(int i = 0; i < input.length; i++) {
for(int compare = i; compare<input.length; compare ++) {
if(i != compare && input[i]==input[compare]) {
repeatCounter++;
if(repeatCounter>=repeater) {
returnValue=input[i];
}
repeater = repeatCounter;
}
repeatCounter=0;
}
}
return returnValue;
}
public static double Median (int[] input) {
Arrays.sort(input);
int output = 0;
double output = 0;
if(input.length%2==0) {
int lowerMiddle = input[(int)input.length/2-1];
int higherMiddle = input[(int)input.length/2];
output = lowerMiddle + higherMiddle;
output = output/2;
}
else {output = input[input.length/2];}
return output;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment