I have arrayA with 20 random elements in the range of 1000.
ArrayA = [133,456,234,512,632,532,234...20];
I need to create new ArrayB and he needs to look like this:
ArrayB = [331(reversed),15(sum of digits),432(reversed),8(sum ofdigits)];
I'm trying to make it without using lists just with methods(for loop and etc.)
My main problem, for now, is that I don't know how to sum digits of the element on even index, and how to create a method for the reversed number on the odd index of the array.
Random random = new Random();
int arrayA[] = new int[20];
for (int i = 0; i < arrayA.length; i++) {
arrayA[i] = random.nextInt(1000);
}
System.out.println("Array A: " + Arrays.toString(arrayA));
int arrayB[] = new int[arrayA.length];
int sum = 0;
for (int i = 0; i < arrayA.length; i++) {
if (i % 2 == 0) {
sum = sum + i % 10;
i = i / 10;
System.out.println(i);
}
}
So again: I need to reverse the number on the odd index and put them in ArrayB in the same index, and I need to sum digits of the element that is on even index and put them in ArrayB. Ofc, an example is on top of my question!