fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(changeLetters("tpttipptptaptptopp"));
  13. System.out.println(changeLetters("TipTop"));
  14. }
  15.  
  16. public static String changeLetters(String str) {
  17. String str1 = "";
  18. for (int i = 0; i < str.length(); i++) {
  19. if (i + 1 >= str.length()) {
  20. str1 += str.charAt(i);
  21. return str1;
  22. }
  23. char ch3 = '\u0000';
  24. char ch1 = str.charAt(i);
  25. char ch2 = str.charAt(i + 1);
  26. if (i + 2 < str.length()) {
  27. ch3 = str.charAt(i + 2);
  28. }
  29. if ((ch1 == 116) && (ch2 == 112)) {
  30. i++;
  31. str1 = str1 + ch1 + ch2;
  32. continue;
  33. } else if ((ch1 == 116) && (ch2 != 112) && (ch3 == 112)) {
  34. i = i + 2;
  35. ch2 = ch3;
  36. str1 = str1 + ch1 + ch2;
  37. } else {
  38. str1 = str1 + ch1;
  39. continue;
  40. }
  41. }
  42. return str1;
  43. }
  44. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
tpttpptptptptpp
TipTop