JAVA exercises

Q 1. Convert from binary to integer
In this class, you have been given a class Challenge with a static method fromBinary. This accepts one string parameter and returns an integer. Complete the method so that it returns decimal value of the binary number supplied in the string parameter.
To make this more challenging and to stop you just going to stack overflow and just find the solution, you need to solve this using only the basic mathematical operators (+, -, *, / , % ) .


Public class Challenge{

Public static int fromBinary(String s)

{

//write your code here

}

}



Public class Main{

Public static void main(String args[])

{

Challenge.fromBinary(“101010101”);
Challenge.fromBinary(“111110101”);
}
}

No comments: