Reversed sum of Reversed Number in java

Reversed sum of Reversed Number is a number in Arabic numericals but the order of digits are reversed . the first digit become last digit and vice versa. note that zero is lost by reversing(eg 1200 gives 21) also note that reversed number never has any trailing zeros. add two reversed number and output their reverse number of course. the result is not unique because any particular number is reversed for number reversing.
SOURCE : ReverseSum.java


public class ReverseSum
{
public static void main(String args[])
{
System.out.println(CalculateReverseSum(24,1));
}

static int CalculateReverseSum(int input1, int input2)
{
int rSum = 0;
int i1 = reverse(input1);
int i2 = reverse(input2);
rSum = reverse(i1+i2);
return rSum;
}

static int reverse(int input)
{
int r = 0;
int reminder =0 ;
while(input!=0)
{
reminder=input%10;
input = input/10;
r= r*10+reminder;
}

return r;
}

}

INPUT

sample input (24,1)




OUTPUT


34







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment