/**
*
* @author Regu Ram
*
*/
import java.util.InputMismatchException;
import java.util.Scanner;
public class Decimal2Binary {
static int decimal;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// Enter a Number to Convert...
try {
decimal = scan.nextInt();
convertToBinary(decimal);
} catch (InputMismatchException e) {
System.err.println("Wrong Input Value, Try Again!");
}
}
public static void convertToBinary(int num){
StringBuilder binary = new StringBuilder();
while(num != 0){
binary.append((num % 2));
num /= 2;
}
System.out.printf("Binary representation of %d is: %s%n", decimal, binary.reverse());
}
}
OUTPUT:
Set Path for java:
Other:
How to set path in java: https://www.youtube.com/watch?v=u9weqPBtgVE
How to run Package Program in java: https://www.youtube.com/watch?v=IfbOZ8i8_A8&t=9s
How to run PHP program: https://www.youtube.com/watch?v=H573Yqr8k4c
How to set path for C#: https://www.youtube.com/watch?v=xDUappFfVJ4
Top 6 operating systems for ethical hackers: https://www.svrrtech.com/2020/02/top-6-operating-systems-for-ethical.html
إرسال تعليق