Step-by-step explanation:
import java.util.Scanner;
import java.math.BigInteger;
public class Main
{
private int x;
public static boolean isValidInteger(String theValue, int theBase)
{
BigInteger number = new BigInteger(theValue,theBase);
if(theValue.equals(number.toString(theBase)))
{
return true;
}
else
return false;
}
public static String convertInteger(String theValue, int initialBase, int finalBase)
{
boolean valid=isValidInteger(theValue,initialBase);
if(valid==true)
{
BigInteger number = new BigInteger(theValue);
return(number.toString(finalBase));
}
else
return("String not in initial base");
}
public static void main(String[] args)
{
System.out.println("Welcome");
String value;
int ibase, dbase;
if(args.length==0)
{
Scanner S = new Scanner(System.in);
System.out.println("Enter Value to be converted :: ");
value = S.nextLine();
System.out.println("Enter initial base :: ");
ibase = S.nextInt();
System.out.println("Enter desired base :: ");
dbase = S.nextInt();
}
else
{
value=args[0];
ibase=Integer.parseInt(args[1]);
dbase=Integer.parseInt(args[2]);
}
System.out.println("Change base "+convertInteger(value,ibase,dbase));
}
}
Output