forked from MLSA-Mehran-UET/learn2code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecimal to binary Convertor.java
More file actions
36 lines (31 loc) · 1.07 KB
/
Copy pathDecimal to binary Convertor.java
File metadata and controls
36 lines (31 loc) · 1.07 KB
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package binaryconvet;
import java.util.Scanner;
/**
*
* @author lenovo
*/
public class BinaryConvet {
// BINARY CONVERTER FUNCTION BELOW:
public static int BinaryConverter(int Input){
//CHECHING IF NUMBER IS ZERO
if (Input == 0)
return 0;
else
//FROMULA OF CONERTING TO BINARY
return (Input % 2 + 10 * BinaryConverter(Input / 2));
}
public static void main(String[] args) {
//CREATING SCANNER CLASS OBJECT TO TAKE INPUT
Scanner s=new Scanner(System.in);
System.out.println("Enter a decimal number ");
//DECIMAL VARIABLE FRO DECIMAL NUMBER
int DecimalNumber=s.nextInt();
//PRINTING AND PASSING ARGUMENTS TO BINARYCONVERTER FUNCTION
System.out.println("Binary number is :"+BinaryConverter(DecimalNumber));
}
}