Write a java program "without using Strings using loops and methods "that lets the user to enter any two integers and weave them digit by digit and print the result of weaving their digits together to form a single number. Two numbers x and y are weaved together as follows. The last pair of digits in the result should be the last digit of x followed by the last digit of y. The second-to-the-last pair of digits in the result should be the second-to- the-last digit of x followed by the second-to-the-last digit of y. And so on.
You should write weaveNumber method that works as following examples weaveNumber( 271 ,389).should return 237819. If one of the numbers has more digits than the other, you should imagine that leading zeros are used to make the numbers of equal length. For example, weaveNumber(2384, 12) should return 20308142 (as if it were a call on weaveNumber(2384, 0012)). Similarly, weaveNumber(9, 318) should return 30198 (as if it were a call on weaveNumber(009, 318)).
Please give thumbs up, thank
sample output:
code:
import java.util.Scanner;
/**
*
* @author VISHAL
*/
public class Weaving {
public static void weaveNumber(int A , int B)
{
int Da=A%10;
int Db=B%10;
if(A==0 && B==0)
{
return;
}
else
{
weaveNumber(A/10,B/10);
}
System.out.print(Da);
System.out.print(Db);
}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter First number : ");
int a=Integer.parseInt(sc.nextLine());
System.out.print("Enter Second number : ");
int b=Integer.parseInt(sc.nextLine());
weaveNumber(a,b);
System.out.println();
}
}
Get Answers For Free
Most questions answered within 1 hours.