Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1.     public static char[] add(char[] arrayOne, char[] arrayTwo, int lengthOne, int lengthTwo)
  2.     {
  3.         char[] sum = new char[20];
  4.         int firstNum, secondNum, smallSum;
  5.  
  6.         for(int i = 0; i < 20; i++)
  7.         {
  8.             firstNum = (Integer.valueOf(arrayOne[i]) - 48); //48 is the offset of the ASCII value
  9.             secondNum = (Integer.valueOf(arrayTwo[i]) - 48);
  10.             smallSum = firstNum + secondNum;
  11.             if(smallSum >= 10)
  12.             {
  13.                 smallSum = smallSum%10;
  14.             }
  15.             sum[i] = Character.forDigit(smallSum, 10);
  16.         }
  17.  
  18.         return sum;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement