Answer to get brainiest. I NEED HELP PLEASE!! I am supposed to type a program on base conversion. Starts from base of 10 (decimal) converted to any base. Must use while loops, if loops, but no for loops.

Answer to get brainiest I NEED HELP PLEASE I am supposed to type a program on base conversion Starts from base of 10 decimal converted to any base Must use whil class=

Respuesta :

tonb

Here's a solution that works except for the leading zeros. Unclear (to me) why they need to be there and what's the logic?


  public static void main(String[] args)  

  {    

       int number, base;

       Scanner Cin = new Scanner(System.in);  

       System.out.print("Enter a decimal number between 1 and 100,000: ");

       number = Cin.nextInt();

       System.out.print("Enter a base from 2-16: ");

       base = Cin.nextInt();          

       System.out.format("The number %d in base %d is %s.", number, base, Integer.toString(number, base).toUpperCase());

  }