[java] Decimal number → n-ary number n-ary number → decimal number

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

[java] Decimal number → n-ary number n-ary number → decimal number
java (random number)
Java Big Decimal
[Java] Use Big Decimal properly ~ 2018 ~
[Java] Random number generation method (Random)
Count the number of digits after the decimal point in Java
Java
Try to implement n-ary addition in Java
Process every arbitrary number in Java List
[Java] Check the number of occurrences of characters
Page number logic and reference code (java)
Cheking Prime number --Java string program examples
Java number guessing game (standard programming problem)