A class Merger concatenates two positive integers that are greater than 0 and produces a new merged integer.
Example: If the first number is 23 and the second is 764, then the concatenated number will be 23764.
Some of the members of the class are given below:
Class name : Merger
Data members/instance variables:
n1 : long integer to store first number
n2 : long integer to store second number
mergNum : long integer to store the merged number
Member functions:
Merger() : constructor to initialize the data members
void readNum( ) : to accept the values of the data members n1 and n2
voidJoinNum( ) : to concatenate the numbers n1 and n2 and store it in mergNum
void show( ) : to display the original numbers and the merged number with appropriate messages
Specify the class Merger, giving the details of the constructor, void readNum(), void JoinNum( ) and void show( ). Define the main( ) function to create an object and call the functions accordingly to enable the task.
import java.util.*;
public class Merger
{
long n1,n2,mergNum;
Merger( )
{
}
OR Merger(){ n1= n2 = mergNum = 0;}
void readNum()
{
Scanner x=new Scanner(System.in);
System.out.println("Enter two numbers");
n1=x.nextLong();
n2=x.nextLong();
}
void JoinNum( )
{
int s=1; long a=n2 ;
while(a!=0)
{
s=s*10;
a=a/10;
}
mergeNum = (n1 * s) +n2;
}