SoloCodigo
		Programación General => Java => Mensaje iniciado por: adn7negro en Viernes 11 de Julio de 2008, 08:19
		
			
			- 
				/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package guilasconversiones;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *  281176
 * @author Ezequiel
 */
public class DecimalBinario {
    public static void main(String[] args) {
        int numero =0;
        int dividendo =0;
        int residuo =0;
        int cociente =0;
        int []binario = new int [16];
        int tamaño = 0;
        
         
        //capturar el numero
           BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
           System.out.print("Introduzca el numero decimal: ");
          
           try { 
            
            
                numero= Integer.parseInt(entrada.readLine()); 
                
            }catch (IOException ex) {System.out.println("Numero Invalido ");
            }catch (NumberFormatException ex) {System.out.println("Numero Invalido ");
            }
            dividendo =numero;
            
            while (dividendo > 0){
                cociente = dividendo / 2;
                residuo = dividendo % 2;
                binario[tamaño] = residuo;
                tamaño = tamaño + 1;
                dividendo = cociente;
                
            }
           //Mostrar el resultado en pantalla
           
           System.out.println("El numero Binario es:  ");
           for (int i =(tamaño-1);i>=0;i--){
               
            System.out.print(+binario);
           }
         
           
    }
}