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
Which are the two subclasses under exception class?
How arrays are stored in memory in java?
Is set ordered?
How many types of design patterns are there?
What is the static variable?
Why does it take so much time to access an applet having swing components the first time?
What methods are used to get and set the text label displayed by a button object?
Define locale.
Does string is thread-safe in java?
Why there are some null interface in java? What does it mean?
how to one war file class to another war file class?
What are the 5 types of research methods?
Difference between Preemptive scheduling vs. Time slicing?
Is class is a data type?
What is the purpose of assert keyword used in jdk1.4.x?