Question: *In Java Given the main method below, write a recursive method called recursion2 in a class called Q2 that accepts two String values as arguments.
*In Java
Given the main method below, write a recursive method called recursion2 in a class called Q2 that accepts two String values as arguments. Assume each string is a valid integer. This method must, starting at the rightmost digit, compute a string representing an integer where the value at each index is the sum of the values at the corresponding index in the two string parameters.
For example:
1234
456
=>1|2|3|4
=> |4|5|6
= 1|6|8|10 = 16810
Another example:
101984
952
=>1|0|1| 9 | 8 |4
=> | | | 9 | 5 |2
= 1|0|1|18|13|6 = 10118136
Sample Output:
Please input the first number: 1234
Please input the second number: 456
16810
Another Sample:
Please input the first number: 101984
Please input the second number: 952
10118136
Main Method:
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("Please input the first number: ");
String s1 = sc.nextLine();
System.out.print("Please input the second number: ");
String s2 = sc.nextLine();
System.out.println(recursion2(s1, s2));
sc.close();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
