Select Menu

Search This Blog

Populer Posts Hari ini

Popular Posts

Powered by Blogger.

Lorem 1

adsense

" });

Circle Gallery

" });

News

" });
» » » source code Konversi Biner ke Desimal dengan Bahasa Java

/*
 * 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 binergajilgenap;

import java.lang.*;
import java.io.*;
import java.util.Scanner;

/**
 *
 * @author andi m
 */
public class BinerGajilGenap {

    /**
     * @param args the command line arguments
     */
   public static void main ( String [] args ) throws IOException{
     Scanner input=new Scanner(System.in);
     System.out.print ( "Masukan Bilangan Binernya = " ) ;
     String str = input.nextLine();
     long num = Long.parseLong(str) ;
     long rem;
     while ( num > 0 ){
       rem = num % 10 ;
       num = num / 10 ;
       if ( rem != 0 && rem != 1 ){
         System.out.println ( "Ini bukan bilangan biner." ) ;
         System.out.println ( "Silahkan Coba lagi" ) ;
         System.exit ( 0 ) ;
       }
     }
     int i= Integer.parseInt ( str,2) ;
     System.out.println ( "Desimalnya : " + i ) ;
   }
}

About andi

«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply