Code doubt ...not able to understand

pls review the code and suggest changes that can be made as i am not able to understand the mistakes that i may have made

bro pls send your code ide link

import java.util.*; public class Main { public static void sumArrays(int[] a,int[] b,int[] c){ int i = a.length; int j = b.length; int k = c.length,carry = 0; while(k>=0){ while(i>=0 && j>=0){ int x = carry; if( a[i] + b[j] < 9){ c[k] = a[i] + b[j] + x; } else if(a[i] + b[j] > 9){ c[k] = (a[i] +b[j]) % 10; carry = (a[i] +b[j]) / 10; } } i–; j–; k–; } for(int x=0;x<c.length;x++){ System.out.print(c[x] + " "); } } public static void main (String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } int m = sc.nextInt(); int[] b = new int[m]; for(int i=0;i<m;i++){ b[i]=sc.nextInt(); } int [] c = new int[n>m ? n:m]; sumArrays(a,b,c); } }

how to generate the link?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

sorry for the late reply
firstly ur code is showing error becoz u have initialized the varible array.length
so pls initialize it with array.length-1

there is small mistake in handling the carry in the code

and resultant array can be of size (bigger array size+ 1) { +1 becoz of last carry}
so use either the string or arraylist to store the resultant

public static void arraySum(int[] one, int[] two) {

    ArrayList ans = new ArrayList<>();

    int i = one.length - 1;
    int j = two.length - 1;

    int carry = 0;
    while (i >= 0 || j >= 0) {

        int sum = carry;

        if (i >= 0) {
            sum += one[i];
        }

        if (j >= 0) {
            sum += two[j];
        }

        int rem = sum % 10;
        ans.add(0, rem);
        carry = sum / 10;

        i--;
        j--;
    }

    if (carry != 0) {
        ans.add(0, carry);
    }

    for (i = 0; i < ans.size(); i++) {
        System.out.print(ans.get(i) + ", ");
    }
    System.out.println("END");
}

hope this will help u
pls rate my work