program: to convert a positive decimal number to Binary, Octail, HexaDecimal
import java.util.*;
public class Conversion{
public static void conversion(int num, int base){
int rem = num%base;
if(num == 0)
return ;
conversion(num/base,base);
if(rem<10)
System.out.printf("%d",rem);
else
System.out.printf("%c",rem-10+'A');
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the base: ");
int base = sc.nextInt();
System.out.println("Enter the number");
int num = sc.nextInt();
conversion(num,base);
}
}
INPUT:
Enter the Base
2
Enter the number
10
OUTPUT
1010
No comments:
Post a Comment
If you have any doubt . Please let me know