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
What is constructor chaining in java?
Can we override a variable in java?
How do I get the | symbol on my keyboard?
What do you understand by the bean persistent property?
How do you create a sop?
What is illegal identifier in java?
which class is the wait() method defined in? : Java thread
What is logical variable?
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?
Difference between collection, collection and collections in java?
What is the use of static class?
How do you replace all in word?
Differentiate between postfix and prefix operators in java.
What is the purpose of javac exe?
What is dynamic array in java?