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 a treemap in java?
What does \ mean in regex?
Define immutable object?
What is unicode full form?
Does a function need a return?
How do you reverse a list?
What are controls and their different types in awt?
What is an anonymous class in java?
Describe 2 different ways to concatenate two strings.
Difference between keyword and identifier.
What is the purpose class.forname method?
What do you know about the garbage collector in java?
How will you get the platform dependent values like line separator, path separator, etc., ?
What is garbage collection? What is the process that is responsible for doing that in java?
Can we clone singleton object in java?