Commit c4fffa49 authored by samuelboulton's avatar samuelboulton

comments

parent 9a8a7f15
......@@ -64,28 +64,6 @@ public class Program {
public static void main(String[] args) {
int[] input = {3,6,77};
double output = 0.0;
double bracketsResult = 0.0;
double powerResult = 0.0;
double total = 0.0;
for(int i = 0; i < input.length; i++)
{
bracketsResult = (double)input[i] / 2.0;
System.out.println(bracketsResult + " bracket result");
powerResult = Math.pow(bracketsResult,i / 2.0);
System.out.println(i + " this is i");
System.out.println(powerResult + " this is powerResult");
total = total + powerResult;
System.out.println(total + " this is total");
}
output = total / (double)(input.length + 3.0);
System.out.println(output + " output");
// TODO Auto-generated method stub
}
......@@ -94,11 +72,13 @@ public class Program {
public static int[] ConvertBinaryToInt(String[] binaryArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[binaryArray.length];
int[] resultsArray = new int[binaryArray.length];
// for loop to go around the binary array
for(int i = 0; i<binaryArray.length; i++)
{
// use the 'ConvertASingleWordToInt' method to work out each character
// then add each character to the resultsArray
resultsArray[i] = ConvertASingleWordToInt(binaryArray[i]);
}
......@@ -108,17 +88,22 @@ public class Program {
public static int ConvertASingleWordToInt(String someWord) {
int result = 0;
int binCM = 1;
// making the characters from said 'someWord'
char[] binChar = someWord.toCharArray();
// looping through the characters
for (int i = 0; i < binChar.length; i++)
{
// making the program go through the characters backwards to get the correct result
int binIndex = binChar.length - i - 1;
// if statement seeing if the character is a 1
if (binChar[binIndex] == '1')
{
// if it is a 1 then do this calcualtion
result = result + binCM;
}
// each time the loop goes round binCM doubles
binCM = binCM * 2;
}
......@@ -130,9 +115,11 @@ public class Program {
public static int[] ConvertHexToInt(String[] hexArray) {
// DONE AND PASSED TEST
int[] resultsArray = new int[hexArray.length];
// for loop to go around the hex array
for(int i = 0; i<hexArray.length; i++) {
// use the 'ConvertHexToInt' method to work out each character
// then add each character to the resultsArray
resultsArray[i] = ConvertHexToInt(hexArray[i]);
}
......@@ -146,9 +133,12 @@ public class Program {
{
int result = 0;
int hexCM = 1;
// making the characters from said 'hexWord'
char[] hexChar = hexWord.toCharArray();
// looping through the characters
for(int i = 0; i < hexChar.length; i++)
{
// if the character is a certain character then do this calculation
int hexIndex = hexChar.length - i - 1;
if(hexChar[hexIndex] == '1') {result = result + (hexCM * 1);}
if(hexChar[hexIndex] == '2') {result = result + (hexCM * 2);}
......
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