Skip to content

Commit d1e86b3

Browse files
Add files via upload
1 parent 449ccf9 commit d1e86b3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: Binary to decimal.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.util.*;
2+
public class Main{
3+
public static void main(String[] args){
4+
Scanner sc=new Scanner(System.in);
5+
long n=sc.nextLong();
6+
int d=0;
7+
int p=0;
8+
while(n!=0){
9+
long rem=n%10;
10+
d+=rem*Math.pow(2,p);
11+
n=n/10;
12+
p++;
13+
}
14+
15+
16+
System.out.print(d);
17+
}
18+
}

0 commit comments

Comments
 (0)