The intent of this page is to collection the best program and help programmers to find good blog posts to read. Some of these blogs may not be written by Java developers, but Java developers should find it useful or interesting. Reading those blogs should be fun and often bring some fresh ideas

Monday, August 3, 2020

Program convert positive decimal to Bin,oct,hec

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

String Operation

String Operation Using collection Framework Sorting Order  public static void sortAccending(String s) { char[] arr = s.toCharArray(); ...

Adbox