Advertisement
AyaAbouzeid

Untitled

May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1.  
  2. public class Tabular {
  3.  
  4.    
  5.    
  6.     String [] decimal;
  7.     String [] binary ;
  8.    
  9.     public Tabular(int length){
  10.        
  11.         decimal = new String [length];
  12.         binary = new String[length];
  13.     }
  14.  
  15.     int placeCounter=0 , max = -1, counterNumber = 0 ;
  16.     public void binary (int number)
  17.     {
  18.  
  19.        decimal[placeCounter] = String.valueOf(number) ;
  20.  
  21.     String remainder= Integer.toBinaryString(number);
  22.         binary[placeCounter] = remainder ;
  23.         counterNumber = remainder.length();
  24.         if (counterNumber>max)
  25.             max = counterNumber;
  26.        
  27.         placeCounter++;
  28.     }
  29.    
  30.    
  31.     public void printdecimal(){
  32.        
  33.         for(int i =0 ; i < decimal.length ; i++ ){
  34.            
  35.             System.out.println(decimal[i]);
  36.         }
  37.        
  38.     }
  39. public void printbinary(){
  40.        
  41.         for(int i =0 ; i < binary.length ; i++ ){
  42.            
  43.             System.out.println(binary[i]);
  44.         }
  45.        
  46.     }
  47.  
  48. public void addZeros (){
  49.     String temp ;
  50.     temp = "";
  51.     for (int i = 0 ; i < placeCounter ; i ++){
  52.  
  53.         if (binary[i].length()< max){
  54.             for (int k=0 ; k< max-binary[i].length() ; k ++){
  55.                 temp = temp + "0";
  56.  
  57.             }
  58.             temp = temp + binary[i];
  59.             binary[i]=temp;
  60.  
  61.             temp="";
  62.            
  63.         }
  64.        
  65.        
  66.     }
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement