Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsBinary To Decimal
https://www.eclipse.org/forums/index.php/mv/msg/404138/945771/#msg_945771
import java.io.*;
import acm.io.*;
public class BinaryToDecimal extends ConsoleProgram {
public void run(){
println(leftBinary()+rightBinary());
}
private int leftBinary(){
int q;
int sum=0;
int count=0;
int a=readInt("how long is your binary number on the left: ");
for(int j=0;j<a;j++){
int n=readInt("Enter number: ");
q= (int) (n *Math.pow(2,j));
count++;
sum+=q;
}
return sum;
}
private double rightBinary(){
double total=0;
double z;
int counter=0;
double b= readInt("how long is your binary number on the right: ");