Translate

Thursday, March 26, 2015

Koding Konversi Bilangan Desimal Ke Biner

import java.util.*;    
public class desimalkebiner

    {

     public static void main(String[] args)


        {   

           Scanner scan = new Scanner(System.in);

           Stack<Integer> stk = new Stack<Integer>();

           System.out.println("Enter decimal number");

           int num = scan.nextInt();
            while (num != 0)


            {

                int d = num % 2;

                stk.push(d);

                num /= 2;

            } 
     

            System.out.print("\nBinary equivalent = ");

            while (!(stk.isEmpty() ))


            {

                System.out.print(stk.pop());

            }

            System.out.println();

        }

    }

No comments:

Post a Comment