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 jpa specification?
How do you escape a string?
Can arraylist hold different types java?
Difference between keyword and identifier.
What is bytecode verifier?
How do you calculate square roots?
Explain listiterator and methods in listiterator?
Which variables are stored in heap?
Is java a software?
What is the gregoriancalendar class in java programming?
Define jit compiler?
What is numeric function?
Can you declare the main method as final?
What is oop principle in java?
How many characters is 2 bytes?