Commit a585857a authored by samuel.boulton's avatar samuel.boulton

4 questions left

parent 08fe03db
......@@ -70,125 +70,81 @@ public class Program {
public static int[] ConvertBinaryToInt(String[] binaryArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[binaryArray.length];
for(int i = 0; i < binaryArray.length; i++)
{
char[] binaryString = binaryArray[i].toCharArray();
int binTotal = 0;
int binCM = 1;
for (int j = 0; j < binaryString.length; j++)
for(int i = 0; i<binaryArray.length; i++)
{
int binIndex = binaryString.length - i - 1;
if (binaryString[binIndex] == '1')
{
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
resultsArray[i] = ConvertASingleWordToInt(binaryArray[i]);
}
return resultsArray;
}
/*for(int i = 0; i<wordArray.length; i++) {
resultsArray[i] = ConvertASingleWordToInt(wordArray[i]);
}*//*
int binTotal = 0;
int binCM = 1;
char[] binCA = binaryArray.toCharArray();
for (int i = 0; i < binCA.length; i++)
{
int binIndex = binCA.length - i - 1;
if (binCA[binIndex] == '1')
{
binTotal = binTotal + binCM;
}
binCM = binCM * 2;
}
System.out.println(binTotal);
*//*
char[] binCA = binaryArray[0].toCharArray();
public static int ConvertASingleWordToInt(String someWord) {
int binTotal = 0;
int result = 0;
int binCM = 1;
for (int i = 0; i < binCA.length; i++)
char[] binChar = someWord.toCharArray();
for (int i = 0; i < binChar.length; i++)
{
int binIndex = binCA.length - i - 1;
if (binCA[binIndex] == '1')
int binIndex = binChar.length - i - 1;
if (binChar[binIndex] == '1')
{
binTotal = binTotal + binCM;
result = result + binCM;
}
binCM = binCM * 2;
}
return resultsArray;
}
*//*
public static int ConvertASingleBinaryToInt(String someBinary) {
int result = 0;
for(int i = 0; i < binaryArray.length; i++)
{
}
if(someBinary == ) {result = 11;}
return result;
}
/*
public static int[] ConvertWordsToInt(String[] wordArray) {
int[] resultsArray = new int[wordArray.length];
public static int[] ConvertHexToInt(String[] hexArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[hexArray.length];
for(int i = 0; i<wordArray.length; i++) {
for(int i = 0; i<hexArray.length; i++) {
resultsArray[i] = ConvertASingleWordToInt(wordArray[i]);
resultsArray[i] = ConvertHexToInt(hexArray[i]);
}
return resultsArray;
}
public static int ConvertASingleWordToInt(String someWord) {
return resultsArray;
}
public static int ConvertHexToInt(String hexWord)
{
int result = 0;
if(someWord == "eleven") {result = 11;}
return result;
int hexCM = 1;
char[] hexChar = hexWord.toCharArray();
for(int i = 0; i < hexChar.length; i++)
{
int hexIndex = hexChar.length - i - 1;
if(hexChar[hexIndex] == '1') {result = result + (hexCM * 1);}
if(hexChar[hexIndex] == '2') {result = result + (hexCM * 2);}
if(hexChar[hexIndex] == '3') {result = result + (hexCM * 3);}
if(hexChar[hexIndex] == '4') {result = result + (hexCM * 4);}
if(hexChar[hexIndex] == '5') {result = result + (hexCM * 5);}
if(hexChar[hexIndex] == '6') {result = result + (hexCM * 6);}
if(hexChar[hexIndex] == '7') {result = result + (hexCM * 7);}
if(hexChar[hexIndex] == '8') {result = result + (hexCM * 8);}
if(hexChar[hexIndex] == '9') {result = result + (hexCM * 9);}
if(hexChar[hexIndex] == 'A') {result = result + (hexCM * 10);}
if(hexChar[hexIndex] == 'B') {result = result + (hexCM * 11);}
if(hexChar[hexIndex] == 'C') {result = result + (hexCM * 12);}
if(hexChar[hexIndex] == 'D') {result = result + (hexCM * 13);}
if(hexChar[hexIndex] == 'E') {result = result + (hexCM * 14);}
if(hexChar[hexIndex] == 'F') {result = result + (hexCM * 15);}
hexCM = hexCM * 16;
}
*/
public static int[] ConvertHexToInt(String[] hexArray) {
int[] resultsArray = new int[hexArray.length];
// same on this question
return resultsArray;
return result;
}
......@@ -253,8 +209,6 @@ public class Program {
resultsArray[i] = intersectList.get(i);
}
return resultsArray;
}
public static int[] Difference(int[] intArrayA, int[] intArrayB) {
......@@ -262,23 +216,26 @@ public class Program {
ArrayList<Integer> differenceList = new ArrayList<Integer>();
for(int j = 0; j < intArrayA.length; j++)
for(int i =0; i < intArrayA.length; i++)
{
for(int k = 0; k < intArrayB.length; k++)
differenceList.add(intArrayA[i]);
}
for(int j =0; j < intArrayB.length; j++)
{
if(intArrayA[j] != intArrayB[k])
differenceList.add(intArrayB[j]);
}
for(int k = 0; k < differenceList.size(); k++)
{
for(int l = 0; l < intArrayB.length; l++)
{
differenceList.add(intArrayA[j]);
if(differenceList.get(k) == intArrayB[l])
{
differenceList.remove(k);
}
}
}
int[] resultsArray = new int[differenceList.size()];
for(int i = 0; i<differenceList.size(); i++) {
resultsArray[i] = differenceList.get(i);
......@@ -287,10 +244,6 @@ public class Program {
return resultsArray;
}
public static int Sum (int[] input) {
int result = 0;
......@@ -323,16 +276,57 @@ public class Program {
return output / input.length;
}
public static int[] ConvertBase20ToInt(String[] b20array) {
public static int[] ConvertBase20ToInt(String[] b20array) {
// DONE AND PASSED TEST
int[] resultsArray = new int[b20array.length];
for(int i = 0; i<b20array.length; i++) {
resultsArray[i] = Convert20ToInt(b20array[i]);
}
return resultsArray;
}
public static int Convert20ToInt(String twentyWord)
{
int result = 0;
int hexCM = 1;
char[] hexChar = twentyWord.toCharArray();
for(int i = 0; i < hexChar.length; i++)
{
int hexIndex = hexChar.length - i - 1;
if(hexChar[hexIndex] == '0') {result = result + (hexCM * 0);}
if(hexChar[hexIndex] == '1') {result = result + (hexCM * 1);}
if(hexChar[hexIndex] == '2') {result = result + (hexCM * 2);}
if(hexChar[hexIndex] == '3') {result = result + (hexCM * 3);}
if(hexChar[hexIndex] == '4') {result = result + (hexCM * 4);}
if(hexChar[hexIndex] == '5') {result = result + (hexCM * 5);}
if(hexChar[hexIndex] == '6') {result = result + (hexCM * 6);}
if(hexChar[hexIndex] == '7') {result = result + (hexCM * 7);}
if(hexChar[hexIndex] == '8') {result = result + (hexCM * 8);}
if(hexChar[hexIndex] == '9') {result = result + (hexCM * 9);}
if(hexChar[hexIndex] == 'A') {result = result + (hexCM * 10);}
if(hexChar[hexIndex] == 'B') {result = result + (hexCM * 11);}
if(hexChar[hexIndex] == 'C') {result = result + (hexCM * 12);}
if(hexChar[hexIndex] == 'D') {result = result + (hexCM * 13);}
if(hexChar[hexIndex] == 'E') {result = result + (hexCM * 14);}
if(hexChar[hexIndex] == 'F') {result = result + (hexCM * 15);}
if(hexChar[hexIndex] == 'G') {result = result + (hexCM * 16);}
if(hexChar[hexIndex] == 'H') {result = result + (hexCM * 17);}
if(hexChar[hexIndex] == 'I') {result = result + (hexCM * 18);}
if(hexChar[hexIndex] == 'J') {result = result + (hexCM * 19);}
hexCM = hexCM * 20;
}
return result;
}
......@@ -371,19 +365,35 @@ public static int Range (int[] input) {
public static int[] ConvertBase3ToInt(String[] b3array) {
// DONE AND PASSED TEST
int[] resultsArray = new int[b3array.length];
for(int i = 0; i<b3array.length; i++)
{
resultsArray[i] = Convert3ToInt(b3array[i]);
}
return resultsArray;
}
public static int Convert3ToInt(String someWord) {
}
int result = 0;
int binCM = 1;
char[] binChar = someWord.toCharArray();
for (int i = 0; i < binChar.length; i++)
{
int binIndex = binChar.length - i - 1;
if (binChar[binIndex] == '1') {result = result + binCM;}
if (binChar[binIndex] == '2') {result = result + (binCM * 2);}
binCM = binCM * 3;
}
return result;
}
......
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