Skip to content

Commit 31fc5cf

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#72 from shivamnew/patch-1
Create bnarytodecimal
2 parents b7f6717 + 760f79d commit 31fc5cf

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

bnarytodecimal

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package lecture3;
2+
import java.util.*;
3+
public class bnarytodecimal {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
Scanner s =new Scanner(System.in);
8+
9+
int N=s.nextInt();
10+
int decimal=0;
11+
for(int i=0;N>0;i++)
12+
{
13+
int r=N%10;
14+
N=N/10;
15+
int c=(int)Math.pow(2,i);
16+
decimal=decimal+r*c;
17+
18+
}
19+
System.out.println(decimal);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)