اكتب برنامج Java لتحويل الرقم الثنائي المعطى إلى الرقم العشري المكافئ له

  • برمجة
  • برمجة جافا

اكتب برنامج Java لتحويل الرقم الثنائي المعطى إلى الرقم العشري المكافئ له

الأجوبة

  1. import java.util.Scanner;
  2. class Binary_Decimal
  3.  {
  4.      Scanner scan;
  5.      int num;
  6.      void getVal() 
  7.       {
  8.                   System.out.println("Binary to Decimal");
  9.    	 scan = new Scanner(System.in);
  10. 	 System.out.println("\nEnter the number :");
  11. 	 num = Integer.parseInt(scan.nextLine(), 2);
  12.       }
  13.     void convert() 
  14.       {
  15.                   String decimal = Integer.toString(num);
  16.    	System.out.println("Decimal Value is : " + decimal);
  17.       }
  18. }
  19. class  MainClass 
  20. {
  21.     public static void main(String args[]) 
  22.       {
  23.           Binary_Decimal obj = new Binary_Decimal();
  24.            obj.getVal();
  25.            obj.convert();
  26.       }
  27. }
  28.  

هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...