fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception {
  11. Scanner scan=new Scanner(System.in);
  12. int A=scan.nextInt();
  13. int B=scan.nextInt();
  14. int [] array=new int[1000];
  15. Arrays.fill(array,0);
  16. int size=add(A,B,array);
  17. for(int i=size-1;i>=0;i--){
  18. System.out.print(array[i]);
  19. }
  20. }
  21. public static int add(int A, int B, int [] array){
  22. int carry=0;
  23. int i=0;
  24. while(A>0 || B>0){
  25. int sum=A%10+B%10+carry+array[i];
  26. array[i]=sum%10;
  27. carry=sum/10;
  28. A=A/10;
  29. B=B/10;
  30. i++;
  31. }
  32. while(carry>0){
  33. int temp=array[i]+carry%10;
  34. array[i]=temp%10;
  35. carry=temp/10;
  36. i++;
  37. }
  38. return i;
  39. }
  40. }
Success #stdin #stdout 0.14s 321088KB
stdin
123 34
stdout
157