Decimal number → n-ary number
import java.io.*;
class file name
{
public static void main(String[]args) throws IOException
{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n What base do you want?(max36):");
String str1 = br.readLine();
int n = Integer.parseInt(str1);
System.out.print("Enter the decimal number you want to convert to n-ary:");
String str2 = br.readLine();
int x = Integer.parseInt(str2);
String A = Integer.toString(x,n);
System.out.println(x+"Is"+n+"In base"+A);
}
}
N-ary number → decimal number
import java.io.*;
class file name
{
public static void main(String[]args) throws IOException
{
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
System.out.print("What decimal number do you want to convert to decimal?:");
String N = br.readLine();
int n=Integer.parseInt(N);
System.out.print("\I want to convert to n10"+n+"Please enter a base number:");
String X = br.readLine();
int A=Integer.parseInt(X,n);
System.out.print("\In n10:"+A);
}
}
Recommended Posts