Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class Test {
- public static void main(String[] args) {
- String str = "xxHxix";
- // String str2= "abbbxxd";
- String str3 = "";
- boolean a = false;
- int leng1 = str.length();
- int count = 0;
- int leng2 = leng1-2;
- if ((str.substring(0,1).equals("x") && str.substring(leng1-1,leng1).equals("x") )) {
- str = str.substring(1, leng1 - 1);
- leng1 = str.length();
- a = true;
- }
- for (int i = 0; i<leng1; i++)
- {
- if (str.substring(i,i+1).equals("x"))
- {
- count++;
- }
- else
- str3 = str3 + str.substring(i,i+1);
- }
- if (a) {
- System.out.println("x" + str3 + "x");
- }
- else
- System.out.println(str3);
- }
- }
Add Comment
Please, Sign In to add comment