File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ #import java .util .*;
2
+ class Binary_Decimal
3
+ {
4
+ public static void main (String args [])
5
+ {
6
+ Scanner sc =new Scanner (System .in );
7
+ int n ,k ,d ,s =0 ,c =0 ;
8
+ n =sc .nextInt ();
9
+ k =n ;
10
+ while (k !=0 )
11
+ {
12
+ d =k %10 ;
13
+ s +=d *(int )Math .pow (2 ,c ++);
14
+ k /=10 ;
15
+ }
16
+ System .out .println ("Binary number:" +n );
17
+ System .out .println ("Decimal equivalent:" +s );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ #import java .util .*;
2
+ class Decimal_Binary
3
+ {
4
+ public static void main (String args [])
5
+ {
6
+ Scanner sc =new Scanner (System .in );
7
+ int n ,k ,s =0 ,c =0 ,d ;
8
+ n =sc .nextInt ();
9
+ k =n ;
10
+ while (k !=0 )
11
+ {
12
+ d =k %2 ;
13
+ s =s +d *(int )Math .pow (10 ,c ++);
14
+ k /=2 ;
15
+ }//converting decimal to binary
16
+ System .out .println ("Decimal number:" +n );
17
+ System .out .println ("Binary equivalent:" +s );
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments