Java Program for Converting Decimal to Binary
Hi Friends.. Today I am going to post a small program to convert any user given decimal number to its corresponding binary value. //DecimalToBinary.java import java.util.Scanner; public class DecimalToBinary { static void decimalToBinary(int value){ int rem =0; String res = "" ; while ( value >0){ rem = value %2; res = res + rem ; value /=2; } System. out .println( new StringBuilder( res ).reverse()); } public static void main(String[] args){ System.out.print("Enter the Decimal Value: "); Scanner scanner = new Scanner(System. in ); int val = scanner .nextInt(); decimalToBinary(val); } } Execute and Enjoy.. 😉