-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask10.java
More file actions
37 lines (37 loc) · 713 Bytes
/
Task10.java
File metadata and controls
37 lines (37 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.*;
class BinaryToDecimal
{
int dec=0;
public int BtoD(int n)
{
int i,v;
int length=String.valueOf(n).length();
for(i=0;i<length;i++)
{
if(n==0)
{
System.out.print("Enter the valid number");
}
else
{
v=n%10;
dec+=v*Math.pow(2, i);
n=n/10;
}
}
return dec;
}
}
class task
{
public static void main(String... args)
{
int Bno,sum;
BinaryToDecimal d = new BinaryToDecimal();
Scanner sc=new Scanner(System.in);
System.out.print("Enter the binary number=");
Bno=sc.nextInt();
sum=d.BtoD(Bno);
System.out.print(sum);
}
}