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
How to stop a thread in java? Explain about sleep () method in a thread?
What are thread local variables?
What about abstract classes in java?
What is class forname used for?
Define jit compiler?
How does list work in java?
Are primitives objects?
Is the milky way in a void?
What are new features introduced with java 8 ?
How does arraylist work in java?
What is meant by javabeans?
Why can't you declare a class as protected?
what is the purpose of using rmisecuritymanager in rmi?
What is the common usage of serialization?
What is the use of private static?