fork(3) download
  1. class PalinTester {
  2.  
  3. public static void main(String[] args) {
  4. System.out.println("Yes:");
  5. printModifiable("010");
  6. printModifiable("0110");
  7.  
  8. System.out.println("No:");
  9. printNotModyfiable("010");
  10. //printNotModyfiable("0110");
  11. }
  12.  
  13. private static void printModifiable(String string) {
  14. StringBuilder sb = new StringBuilder(string);
  15. for (int i = 0; i <= string.length(); i++) {
  16. sb.insert(i, 'X');
  17. System.out.println(sb);
  18. sb.delete(i, i + 1);
  19. }
  20. }
  21.  
  22. private static void printNotModyfiable(String string) {
  23. StringBuilder sb = new StringBuilder(string);
  24. for (int i = 0; i <= string.length(); i++) {
  25. sb.insert(i, 'X');
  26. for (int j = 0; j <= sb.length(); j++) {
  27. sb.insert(j, 'Y');
  28. System.out.println(sb);
  29. sb.delete(j, j + 1);
  30. }
  31. sb.delete(i, i + 1);
  32. }
  33. }
  34. }
  35.  
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Yes:
X010
0X10
01X0
010X
X0110
0X110
01X10
011X0
0110X
No:
YX010
XY010
X0Y10
X01Y0
X010Y
Y0X10
0YX10
0XY10
0X1Y0
0X10Y
Y01X0
0Y1X0
01YX0
01XY0
01X0Y
Y010X
0Y10X
01Y0X
010YX
010XY