Need some help with decimal to base conversion!!

I am writing a program to convert a base 10 integer to any base 2-16. Here are the terms:

"The method is to convert the decimal value the user selected into whatever base the user selected and print the converted value one place value at a time by using an index into an array of characters 0-9 amd A-F that is initialized to contain those characters.

In the method you will find the largest place value (i.e. power of the base) that will divide into the decimal number.

Then you can set up a loop that will operate from that power down to and including the 0th power to determine how many times each place value goes into the decimal number. Using the loop counter, index into the character array to print the character that corresponds to the quotient number and then subtract the product of the place value and the quotient from the decimal number. With the power (loop index) decreased, repeat until you finish the 0th place value.

Here's what I have so far:

import java.io.*;

import java.util.Scanner;

public class ConvertIt

{//start program

public static void main(String[] args)

{//start main

Scanner input = new Scanner(System.in);

System.out.println("Enter a positive integer from 0 to 10000.");

int number = input.nextInt();

System.out.println("Enter the base to convert to.");

int base = input.nextInt();

convertIt(number, base);

}//end main

public static void convertIt(int number, int base)

{//start method

int array = {0123456789ABCDEF};

while (number != 0 && < 10000)

{//start while

}//end while

for (int i = array.length-1; i > -1; i--)

{//start for

}//end for

}//end while

}//end method

}//end program

I think I have it set up correctly, I'm just not sure how to attack it. I understand the concept of what I'm doing, just not the execution of it.

Re: Need some help with decimal to base conversion!!

First, please place your code between code tags [CODE][/CODE]. There are some syntax errors above. The int array is not initialized correctly or with the correct values for an integer array. Also, your while loop conditional is incorrectly constructed. I suggest you fix these and add the algorithm you described and see if it compiles and then if it works. If not, we will still be here to help.

Examples of correct syntax.

Code:

`int myArray[] = {1,2,3,4,5,6};`

char charArray[] = {'1', '2', '3', '4', 'e', 'f', 'g' };

while (a < 100 && b > 2000) {

// manipulate a and b

}

Regards,

Jim