Guest

Prevody

By: a guest on Nov 7th, 2010  |  syntax: Java  |  size: 0.95 KB  |  hits: 60  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. /**
  2.  *
  3.  * @author Felix
  4.  */
  5. public class Prevody{
  6.  
  7.     public StringBuffer sb = new StringBuffer();
  8.     public boolean DEBUG = false;
  9.  
  10.     public void KlasickyPrevod(int num,int f){
  11.        System.out.println("Prevadene cislo:"+Integer.toString(num));
  12.        System.out.println("Prevodni soustava:"+Integer.toString(f));
  13.        int w;
  14.         while(num!=0){
  15.             if(DEBUG){
  16.                 System.out.println("Deleni "+Integer.toString(num)+"/"+Integer.toString(f)+" zbytek:"+Integer.toString(num%f));
  17.             }
  18.             w = num%f;
  19.             num = num/f;
  20.             sb.append(w);
  21.         }
  22.         sb.reverse();
  23.         System.out.println("Vysledek="+sb);
  24.     }
  25.  
  26.     public static void main(String[] args) {
  27.        Prevody p = new Prevody();
  28.  
  29.        // prevadene cislo
  30.        int cislo = 120;
  31.        // prevodni soustava
  32.        int soustava = 2;
  33.  
  34.        // defaultne je nastaveny vysledek v 10kove soustave
  35.        p.KlasickyPrevod(cislo,soustava);
  36.     }
  37.  
  38. }