0% found this document useful (0 votes)
58 views

Processing Two Words

This method takes a string and integer input, splits the string into an array of words, uses integer division and modulo to select the nth words, reverses the first half of characters in the selected words, and returns a string combining the modified words separated by a space.

Uploaded by

mohan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Processing Two Words

This method takes a string and integer input, splits the string into an array of words, uses integer division and modulo to select the nth words, reverses the first half of characters in the selected words, and returns a string combining the modified words separated by a space.

Uploaded by

mohan
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

public static String TwoWOds(String Str,int input2)

{
String st[]=Str.split("\\s");
int w1=input2/10;
int w2=input2%10;
String ww0=st[w1-1];
String ww1=st[w2-1];
int len=ww0.length()/2-1;
if(ww0.length()%2!=0)
len++;
String temp="";
for(int i=len;i>-1;i--)
{
temp=temp+ww0.charAt(i);
}
temp+=ww0.substring(ww0.length()/2);
ww0=temp;
len=ww1.length()/2-1;
if(ww1.length()%2!=0)
len++;
temp="";
for(int i=len;i>-1;i--)
{
temp=temp+ww1.charAt(i);
}
temp+=ww1.substring(ww1.length()/2);
ww1=temp;
return ww0+" "+ww1;
}

You might also like