• Jueves 2 de Mayo de 2024, 06:03

Autor Tema:  Decimal a Octal, Código  (Leído 1962 veces)

adn7negro

  • Nuevo Miembro
  • *
  • Mensajes: 8
    • Ver Perfil
Decimal a Octal, Código
« en: Viernes 11 de Julio de 2008, 08:20 »
0
/*
 * 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;

/**
 *
 * @author Ezequiel
 */
public class DecimalOctal {
public static void main(String[] args) {
        int numero =0;
        int dividendo =0;
        int residuo =0;
        int cociente =0;
        int []octal = new int [16];
        int tamaño = 0;
       
         
        //Capturamos 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 ");
            }
           
           //Guardamos el numero ingresado en pantalla en la variable dividendo
            dividendo =numero;
            //Realizar operaciones y almacenar en vector con tamaño definido por contador
            while (dividendo > 0){
                cociente = dividendo / 8;
                residuo = dividendo % 8;
                octal[tamaño] = residuo;
                tamaño = tamaño + 1;
                dividendo = cociente;
               
            }
           
           //Mostrar el resultado en pantalla
           System.out.println("El numero Octal es:  ");
           for (int i =(tamaño-1);i>=0;i--){
               
            System.out.print(+octal);
           }
         
           
    }
}