here is question Write a method that generates an int array as a parameter, converts the generated integers into characters and print the new char array. Array values should be in the range [0 -255].
public static void main(String[] args) {
char[] array1 = new char [100];
int d;
int[] array = getArray();
convert(array,array1);
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
for (int i = 0; i < 100; i++) {
System.out.print(array1[i] + " ");
}
}
public static int convert(int[] array, char[] array1) {
for (int a=0;a<100;a++) {
array [a] = toChars(array1[a]);
}
}
public static int[] getArray() {
int[] array = new int[100];
for (int i = 0; i < array.length; i++) {
array[i] = (int)(Math.random() * 255);
}
System.out.println();
return array;
}
I have encountered few problem with that. I could not convert integer to ASCII code. What I can use instead of:
for (int a=0;a<100;a++) {
array [a] = toChars(array1[a]);
}