Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Binary To Decimal(i am trying to code a binary to decimal program that could take numbers llike 11.111. this is what i have for now. if anyone could look at it for me, i would be glad)
Binary To Decimal [message #945771] Mon, 15 October 2012 16:23
oti agyei is currently offline oti agyeiFriend
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 ;

}
}




Previous Topic:Ran into a JDK error
Next Topic:in eclipse juno the window's size can not be set by configurer.setInitialSize
Goto Forum:
  


Current Time: Sat Apr 20 01:38:39 GMT 2024

Powered by FUDForum. Page generated in 0.08368 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top