Javatpoint Logo

String weaver plzz help to this

By: balaji*** On: Wed Feb 22 23:24:09 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
Name of method getWeavedString()

Arguments: two arguments of type strings

Return Type: an string value

Specifications: The value returned by the method getWeavedString() is determined by the following rules

Values must not be blank. If yes, then return -1 as string.

If value1 is greater than value2 in length, then return a concatenated string which looks like value2+value1+value2.

If value1 is smaller than value2 in length, then return a concatenated string which looks like value1+value2+value1.

If value1 equal to value2 in length, then return a concatenated string which contains each character from both the values at the same position. For e.g."Hello" "Hello" result = "HHeelloo"
Up0Down

 
public class ECC_35_StringWeaver
{

public static void main(String[] args)
{
String s1="talent";


String s2="sprint";


System.out.println(ECC_35_StringWeaver.getWeavedString(s1,s2));
}
public static String getWeavedString(String value1,String value2)
{
String c1="";
String c2="";

int l1=value1.length();
int l2=value2.length();
if(l1==0||l2==0)
return "-1";
if(l1>l2)
return value2+value1+value2;
if(l1<l2)
return value1+value2+value1;
if(l1==l2)

c1 = String.valueOf(value1.charAt(0));
String A1 = String.valueOf(value1.charAt(1));
String A2 = String.valueOf(value1.charAt(2));
String A3 = String.valueOf(value1.charAt(3));
String A4 = String.valueOf(value1.charAt(4));
c2 = String.valueOf(value2.charAt(0));
String B1 = String.valueOf(value2.charAt(1));
String B2 = String.valueOf(value2.charAt(2));
String B3 = String.valueOf(value2.charAt(3));
String B4 = String.valueOf(value2.charAt(4));
return c1+c2+A1+B1+A2+B2+A3+B3+A4+B4;



}

}
Image Created0Down

By: [email protected] On: Wed Feb 22 23:25:05 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No