0 votes
Write a program 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. Sep 20, 2019 in Java 167 views

## 1 answer to this question.

0 votes

You can use this code:

```import java.util.*;

public class sample{

public static void main(String args[])

{

System.out.println("Enter value of X");

Scanner in = new Scanner(System.in);

String x = in. nextLine();

int x_int = Integer.parseInt(x);

int length_x = String.valueOf(x).length();

System.out.println("Enter value of Y");

String y = in. nextLine();

int y_int = Integer.parseInt(y);

int length_y = String.valueOf(y).length();

int result=0;

int temp;

int min;

if(y_int>x_int) {

min=length_x;

}

else {

min=length_y;

}

for(int i=1;i<=min;i++)

{

int dig = String.valueOf(result).length();

temp=y_int%10;

for (int j=0;j<dig;j++)

{

temp=temp*10;

}

result = result+temp;

y_int=y_int/10;

dig = String.valueOf(result).length();

temp=x_int%10;

for (int j=0;j<dig;j++)

{

temp=temp*10;

}

result = result+temp;

x_int=x_int/10;

}

if(y_int>x_int) {

for(int i=1;i<=length_y-min;i++)

{

int dig = String.valueOf(result).length();

temp=y_int%10;

for (int j=0;j<dig;j++)

{

temp=temp*10;

}

result = result+temp;

y_int=y_int/10;

}

}

else if(y_int<x_int){

for(int i=1;i<=length_x-min;i++)

{

int dig;

dig = String.valueOf(result).length();

temp=x_int%10;

for (int j=0;j<dig;j++)

{

temp=temp*10;

}

result = result+temp;

x_int=x_int/10;

}

}

System.out.println("Result = "+result/10);

}

}``` answered Sep 23, 2019 by
• 69,110 points

0 votes
3 answers

## How can I add new elements to an Array in Java

String[] source = new String[] { "a", ...READ MORE

0 votes
2 answers

## How can I convert an 'ArrayList<String> to 'String[]' in Java

In Java 8 or later: String listString = ...READ MORE

0 votes
1 answer

## How can I Sort an ArrayList in Java

You can sort the ArrayList in 2 ...READ MORE

0 votes
6 answers

## How can I separate the digits of an int number in Java?

You can also have a look here: To ...READ MORE

0 votes
2 answers

## How can I solve java.lang.NoClassDefFoundError in Java?

NoClassDefFoundError means that the class is present ...READ MORE

0 votes
1 answer

## How can I solve this: To prevent a memory leak, the JDBC Driver has been forcibly unregistered

What can you do? Ignore these warnings. Tomcat ...READ MORE

0 votes
2 answers

## How can I convert a String variable to a primitive int in Java

Here are two ways illustrating this: Integer x ...READ MORE

0 votes
2 answers

## How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

+15 votes
25 answers

## How can I convert String to JSON object in Java?

Hi @Daisy You can use Google gson  for more ...READ MORE

+28 votes
3 answers

## How can we set java.library.path in Eclipse?

Go into the library settings for your ...READ MORE