# converting an int value into an int array

**807599**Apr 8, 2007 1:20 AM

I am trying to create a method that will receive an int value and determine each digit within the value. It will then return an int array of all the individual digits in value. If value = 6358, the array would store 6 in the first position, 3 in the second, 5 in the third, and 8 in the fourth.

Basically this is what I have gotten thus far, however I can't get it to compile.

class test {

public static void main(String args[]) {

System.out.print("Please enter a value of any size: ");

int value = UserInput.readInt();

digits(value, 0);

}

public static void digits(int value, int i) { //this creates the size of my int array

boolean stop;

stop = true;

for (i = 0; stop; i++) {

double compare = Math.pow(10, i);

if (value > compare && value < (compare*10)) {

stop = false;

}

}

digits(value, i, 0);

}

public static int[] digits(int value, int i, int index) {

int[] digits = new int

Basically this is what I have gotten thus far, however I can't get it to compile.

class test {

public static void main(String args[]) {

System.out.print("Please enter a value of any size: ");

int value = UserInput.readInt();

digits(value, 0);

}

public static void digits(int value, int i) { //this creates the size of my int array

boolean stop;

stop = true;

for (i = 0; stop; i++) {

double compare = Math.pow(10, i);

if (value > compare && value < (compare*10)) {

stop = false;

}

}

digits(value, i, 0);

}

public static int[] digits(int value, int i, int index) {

int[] digits = new int

*;*

int temp = value;

int temp2 = value;

for (int user = (i-1); user > 0; user--) {

double power = Math.pow(10, user);

temp /=(Math.pow(10, user));

digits[index++] = temp;

temp = (value - (temp * power));

value = temp;

}

for (int j = 0; j < i; j++) {

System.out.println(digits[i]);

}

return digits;

}

}int temp = value;

int temp2 = value;

for (int user = (i-1); user > 0; user--) {

double power = Math.pow(10, user);

temp /=(Math.pow(10, user));

digits[index++] = temp;

temp = (value - (temp * power));

value = temp;

}

for (int j = 0; j < i; j++) {

System.out.println(digits[i]);

}

return digits;

}

}

- 8 Views
- Tags: none (add)