Advertisement
brilliant_moves

Dec2Bin.java

Sep 7th, 2012
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.55 KB | None | 0 0
  1. public class Dec2Bin {
  2.  
  3.     /**
  4.       * Program:    Dec2Bin.java by Chris Clarke
  5.       * Created:    21.09.2009
  6.       * Purpose:    Convert decimal to binary and display result
  7.       **/
  8.  
  9.     public static String convertDec2Bin(String s) {
  10.         int dec = Integer.parseInt(s);
  11.         return toBinary(dec);
  12.     }
  13.  
  14.     static String toBinary(int num) { return Integer.toBinaryString(num); }
  15.  
  16.     public static void main(String[] args) {
  17.         if (args.length==1) {
  18.             System.out.println( convertDec2Bin( args[0]));
  19.         } else
  20.             System.out.println("Use: \"java Dec2Bin <decimal number>\"");
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement