Logical and
Problem solving based questions
Here we include the questions based on the
logical ability and problem solving using java language-
1. Reverse
a string in give size of chunk like – abcdefgh – cbafedhg
package
com.mk.logicaltest.stringproblem;
public class
ReversString {
public static void
main(String[] args) {
System.out.println(reverseStringInSubString("abcdefgh", 3));
}
private static String
reverseStringInSubString(String str, int subStrSize) {
int index = 0;
StringBuilder revstrBuilder = new
StringBuilder();
while(index < str.length())
{
String sub;
if(index+subStrSize > str.length())
{
sub = str.substring(index);
} else {
sub = str.substring(index, index+subStrSize);
}
StringBuilder strBuilder = new
StringBuilder();
strBuilder.append(sub);
revstrBuilder.append(strBuilder.reverse());
index +=subStrSize;
}
return revstrBuilder.toString();
}
}
Nice information, very usefull thanks
ReplyDelete