I need help please send me reply:
Write a program "if given a string like 'HAT', the
combination's returned should be like ATH,THA,TAH in java"?

Answer Posted / g.s.reddy

public class Example {
public static void main(String args[]) throws Exception {
String input = "HAT";
showPattern("", input);
}
public static void showPattern(String st, String chars) {
if (chars.length() <= 1)
System.out.println(st + chars);
else
for (int i = 0; i < chars.length(); i++) {

try {
String newString = chars.substring(0, i)
+ chars.substring(i + 1);
showPattern(st + chars.charAt(i),newString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is constructor chaining in java?

807


Can we override a variable in java?

747


How do I get the | symbol on my keyboard?

771


What do you understand by the bean persistent property?

751


How do you create a sop?

726


What is illegal identifier in java?

743


which class is the wait() method defined in? : Java thread

705


What is logical variable?

719


What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?

2193


Difference between collection, collection and collections in java?

781


What is the use of static class?

764


How do you replace all in word?

704


Differentiate between postfix and prefix operators in java.

859


What is the purpose of javac exe?

759


What is dynamic array in java?

730