Merge pull request #791 from Priyansh-Kedia/master
Update BinaryToDecimal.java
This commit is contained in:
commit
acb40ef3b0
@ -15,14 +15,14 @@ class BinaryToDecimal {
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int n, k, d, s = 0, c = 0;
|
||||
int binNum, binCopy, d, s = 0, power = 0;
|
||||
System.out.print("Binary number: ");
|
||||
n = sc.nextInt();
|
||||
k = n;
|
||||
while (k != 0) {
|
||||
d = k % 10;
|
||||
s += d * (int) Math.pow(2, c++);
|
||||
k /= 10;
|
||||
binNum = sc.nextInt();
|
||||
binCopy = binNum;
|
||||
while (binCopy != 0) {
|
||||
d = binCopy % 10;
|
||||
s += d * (int) Math.pow(2, power++);
|
||||
binCopy /= 10;
|
||||
}
|
||||
System.out.println("Decimal equivalent:" + s);
|
||||
sc.close();
|
||||
|
Loading…
Reference in New Issue
Block a user