FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java_Fundamentals/BinarytoDecimal.java at main · devdeepak06/Java_Fundamentals · GitHub
devdeepak06
/
Java_Fundamentals
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java_Fundamentals
/
BinarytoDecimal.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (42 loc) · 1.08 KB
Breadcrumbs
Java_Fundamentals
/
BinarytoDecimal.java
Copy path
File metadata and controls
44 lines (42 loc) · 1.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
38
39
40
41
42
43
44
// write a program that converts a binary number to a decimal number
//
// Input Format:
// Integer n
//
// Constraints:
// 0 <= n <= 1000000000
//
// Output Format
// Decimal number
//
// Sample Input
// 1100
// Sample Output
// 12
// Explanation
// For the given input, you have to print the decimal equivalent of it. Hence, 12.
//
// Sample Input
// 111
// Sample Output
// 7
// Explanation
// For the given input, you have to print the decimal equivalent of it. Hence, 7.
//
import
java
.
util
.
Scanner
;
public
class
BinarytoDecimal
{
public
static
void
main
(
String
[]
args
) {
try
(
Scanner
s
=
new
Scanner
(
System
.
in
)) {
int
n
=
s
.
nextInt
();
int
dec
=
0
;
int
pow
=
0
;
while
(
n
>
0
) {
int
rem
=
n
%
10
;
dec
=
dec
+
rem
* (
int
)
Math
.
pow
(
2
,
pow
);
pow
++;
n
=
n
/
10
;
}
System
.
out
.
println
(
dec
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL