xxxxxxxxxx
public class ArraySum {
public static void main(String[] args) {
int first = Integer.parseInt(args[0]);
int[] firstArray = transform(first);
int second = Integer.parseInt(args[1]);
int[] secondArray = transform(second);
int[] result = sum(firstArray, secondArray);
print(result);
}
public static int[] transform(int num){
// TODO change only the following part.
}
public static int[] sum(int[] a, int[] b){
// TODO change only the following part.
}
public static void print(int[] array){
System.out.print("[");
for (int i = 0; i < array.length; i++){
if(i != array.length - 1) {
System.out.print(array[i] + ", ");
}else{
System.out.print(array[i] + "]");
}
}
}
}
xxxxxxxxxx
int number = 110101;
String temp = Integer.toString(number);
int[] numbers = new int[temp.length()];
for (int i = 0; i < temp.length(); i++) {
numbers[i] = temp.charAt(i) - '0';
}
xxxxxxxxxx
public class NumberToArray {
public static void main(String[] args) {
int number = 12345;
int[] digitArray = convertNumberToArray(number);
for (int digit : digitArray) {
System.out.print(digit + " ");
}
}
public static int[] convertNumberToArray(int number) {
int numDigits = (int) Math.log10(number) + 1; // Calculate the number of digits
int[] digitArray = new int[numDigits];
for (int i = numDigits - 1; i >= 0; i--) {
digitArray[i] = number % 10; // Extract the last digit
number /= 10; // Remove the last digit
}
return digitArray;
}
}
xxxxxxxxxx
int[] oldArray;
// Here you would assign and fill oldArray
Integer[] newArray = new Integer[oldArray.length];
int i = 0;
for (int value : oldArray) {
newArray[i++] = Integer.valueOf(value);
}