Código Java – Cambiar de Base


//Codificado por: sAfOrAs
import javax.swing.JOptionPane;
import java.lang.*;
public class CambiarBase
{
	static String numD="",pos="",conversion="";
	static int sistO,sistD;
	public static void main(String[] args)
	{

	}

	public static void leer()
	{

		do{
		sistD=Integer.parseInt(JOptionPane.showInputDialog("Ingrese el numero de la base del sistema destino"));
			if(sistD>9 || sistD<2 )
				JOptionPane.showMessageDialog(null,"Se admite bases de 2 a 9");
		}while(sistD>9 || sistD<2);
		sistO=10;
	}

	public static void desde_base_decimal(String numO)
	{
		leer();
		numD="";
		while(Integer.parseInt(numO)>=sistD)
		{
			pos=String.valueOf(Integer.parseInt(numO)%sistD);

			numO=String.valueOf(Integer.parseInt(numO)/sistD);
			numD+=pos;
		}
		pos=numO;
		numD+=pos;
		invertir_cadena(numD,sistD);
		limpiarValores();
	}

	public static void limpiarValores()
	{
		numD="";pos="";conversion="";
		sistO=0;sistD=0;
	}

	public static void invertir_cadena(String numD,int sistD)
	{
		for(int i=numD.length();i>0;i--)
		{
			conversion+=numD.substring((i-1),i);
		}
		JOptionPane.showMessageDialog(null,"Transformacion: \n"+"Es igual a: "+ conversion+" en base "+sistD);
	}

}
Anuncio publicitario

Un comentario sobre “Código Java – Cambiar de Base

  1. Wonderful blog you have here but I was wanting to know if you knew of any
    discussion boards that cover the same topics discussed in this article?
    I’d really love to be a part of online community where I can get advice from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Thank you!

Deja tu comentario

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s