diff --git a/src/com/interview/array/ArrayAddition.java b/src/com/interview/array/ArrayAddition.java index 7ad37269..7bf3d862 100644 --- a/src/com/interview/array/ArrayAddition.java +++ b/src/com/interview/array/ArrayAddition.java @@ -2,7 +2,7 @@ public class ArrayAddition { - public int[] add(int arr1[], int arr2[]){ + public int[] add(int arr1[], int arr2[]) { int l = Math.max(arr1.length, arr2.length); int[] result = new int[l]; int c=0; @@ -10,24 +10,24 @@ public int[] add(int arr1[], int arr2[]){ int j= arr2.length-1; int r=0; l--; - while(i >=0 && j >=0){ + while (i >=0 && j >=0) { r = arr1[i--] + arr2[j--] + c; c = r/10; result[l--] = r%10; } - while(i>=0){ + while (i>=0) { r = arr1[i--] + c; c = r/10; result[l--] = r%10; } - while(j>=0){ + while (j>=0) { r = arr2[j--] + c; c = r/10; result[l--] = r%10; } - if(c != 0){ + if (c != 0) { int[] newResult = new int[result.length+1]; - for(int t= newResult.length-1; t> 0; t--){ + for (int t= newResult.length-1; t> 0; t--) { newResult[t] = result[t-1]; } newResult[0] = c; @@ -36,13 +36,13 @@ public int[] add(int arr1[], int arr2[]){ return result; } - public static void main(String args[]){ + public static void main(String args[]) { int arr1[] = {9,9,9,9,9,9,9}; int arr2[] = {1,6,8,2,6,7}; ArrayAddition aa = new ArrayAddition(); int result[] = aa.add(arr1, arr2); - for(int i=0; i < result.length; i++){ + for (int i=0; i < result.length; i++) { System.out.print(" " + result[i]); } }