Guest User

Untitled

a guest
Mar 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. package com.company;
  2. public class Test {
  3. public static void main(String[] args) {
  4.  
  5. String str = "xxHxix";
  6. // String str2= "abbbxxd";
  7. String str3 = "";
  8. boolean a = false;
  9. int leng1 = str.length();
  10. int count = 0;
  11. int leng2 = leng1-2;
  12. if ((str.substring(0,1).equals("x") && str.substring(leng1-1,leng1).equals("x") )) {
  13. str = str.substring(1, leng1 - 1);
  14. leng1 = str.length();
  15. a = true;
  16. }
  17. for (int i = 0; i<leng1; i++)
  18. {
  19. if (str.substring(i,i+1).equals("x"))
  20. {
  21. count++;
  22. }
  23. else
  24. str3 = str3 + str.substring(i,i+1);
  25. }
  26.  
  27.  
  28. if (a) {
  29. System.out.println("x" + str3 + "x");
  30. }
  31. else
  32. System.out.println(str3);
  33. }
  34. }
Add Comment
Please, Sign In to add comment