| Binary To Decimal [message #945771] |
Mon, 15 October 2012 12:23 |
oti agyei Messages: 1 Registered: October 2012 |
Junior Member |
|
|
import acm.program.*;
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: ");
for(int d=1;d<=b;d++){
int e=readInt("Enter number: ");
for(int p=1;p<3;p++){
z=(double) (e*Math.pow(2,-p));
counter++;
total+=z;
}
}
return total;
}
private double BinToDin(){
double U;
U=leftBinary()+rightBinary();
return U ;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04270 seconds