4.userid Generation Question and Answers
4.userid Generation Question and Answers
import java.io.*;
import java.util.*;
}
else //step1: if lengths of input1 and input2 are equal
{
for(int i=0;i<l1;i++)
{
if(input1.charAt(i)<input2.charAt(i))
{
small=input1;
longer=input2;
f=1;
break;
}
else if(input2.charAt(i)<input1.charAt(i))
{
small=input2;
longer=input1;
f=1;
break;
}
else
{
continue;
}
}
if(f==0) // if both the strings are equal
{
small=input1;
longer=input2;
}
}
String userid="";
char ar1[]=small.toCharArray(); // convert small string into character array
char ar2[]=longer.toCharArray(); // convert longer string into character array
String s1=String.valueOf(ar1[ar1.length-1]); // step2: get the last char of small and convert it into string
String s2=longer; // step2: get the entire longer string
char ar3[]=String.valueOf(input3).toCharArray(); // convert input3 into string and convert into char
array
String s3=String.valueOf(ar3[input4-1]); // step2: get the nth value from input3 by traversing from left to
right
String s4=String.valueOf(ar3[ar3.length-input4]); // step2: get the nth value from input3
by traversing from right to left
userid=s1+s2+s3+s4; // combine all the strings
String res="";
for(int i=0;i<userid.length();i++) // step3: convert the lowercase character into uppercase and
uppercase charcter into lowercase
{
if(Character.isLowerCase(userid.charAt(i)))
{
res=res+Character.toUpperCase(userid.charAt(i));
}
else
{
res=res+Character.toLowerCase(userid.charAt(i));
}
}
return res;
}
}