Created
December 28, 2023 23:08
-
-
Save iamgauravbisht/6e8612a392eae3036a59eaf033d03312 to your computer and use it in GitHub Desktop.
Decimal To Binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package BinaryAndDecimal; | |
import java.util.Scanner; | |
// Decimal to Binary Conversion | |
public class DecimalToBinary { | |
public static void main(String[] args) { | |
Scanner s=new Scanner(System.in); | |
System.out.print("Enter a number : "); | |
int decimal = s.nextInt(); | |
String result =""; | |
while(decimal>0){ | |
int rem = decimal%2; | |
decimal = decimal/2; | |
result= rem + result; | |
} | |
System.out.println("Binary :" + result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment