Is this useful to you at all?
- Main now has 2 arrays declared in it called intArray and charArray. intArray is for the storage of the values created in numbers.
- Numbers() method takes the intArray, stores the values for later use but also prints out each value to the screen...as you wanted.
- Convert() method takes the filled intArray and the empty charArray and converts each of the numbers (0 - 9) to their respective char version using the Character method, forDigit(). Then they are stored in charArray.
- charArray is printed to the screen.
*NOTE* Character.forDigit(numbers[x], 10) is there because I know the values wont exceed past the value 9. This won't work if your values exceed the value 9. public class Example2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //DECLARE ARRAYS int[] intArray = new int[10]; char[] charArray = new char[10]; //call method //this works to call the method of numbers below intArray = Numbers(intArray); //call method to convert string of numbers to character Array charArray = Convert(intArray, charArray); //print charArray to screen for(int i = 0; i < 10; i++) { System.out.print(charArray[i] + " "); } } public static int[] Numbers(int[] numbers) { System.out.print("These are the ints: "); for (int i = 0; i < 10; i++) { numbers[i] = i;//Store number in an integer array System.out.print(numbers[i] + " "); //Print each number to screen } System.out.println(""); return numbers; } //Returns an array of numbers as characters //@PARAM The array to be converted //and The array to store the conversions public static char[] Convert(int[] numbers, char[] converted) { System.out.print("These are the chars: "); for(int i = 0; i < converted.length; i++) { converted[i] = Character.forDigit(numbers[i], 10); } return converted; } } Output:
L:\Code\Java\java Exercise2
These are the ints: 0 1 2 3 4 5 6 7 8 9
Theses are the chars: 0 1 2 3 4 5 6 7 8 9