Remove
Remove "X" inString Problem Solution in Java | Capgemini ADAPT Solutions 2022 using Java

In this post, you will get the solution to the Capgemini ADAPT 2022 solution to the problem of Remove “X” inString in Java. Capgemini ADAPT Java Solutions 2022, Remove “X” inString.

Note: The solutions are provided for learning purposes only. 

Remove “X” inString Problem Description:


Given a string, return a version where all the “x” have been removed. Except an “x” at the very start or end should not be removed.

  1. Create a method with the following syntax shown below to write the logic.

public static String removeX(String str);

Note: Use Scanner to read the String from the Console.

Sample Input:


xxHxix

Sample Output:


xHix

Execution Time Limit:


10 seconds

Capgemini ADAPT 2022 – Remove “X” inString Problem Solution in Java:


import java.io.*;

import java.util.*;

import java.text.*;

import java.math.*;

import java.util.regex.*;

public class Source{

public static String stringX(String str){

int len = str.length();

if(len<3){

return str;

}

String subStr = str.substring(1, len – 1);

subStr = subStr.replace(“X”, “”);

return str.charAt(0)+subStr+str.charAt(len – 1);

}

public static void main(String args[]) throws Exception {

Scanner sc = new Scanner(System.in);

String str = sc.next();

System.out.println(stringX(str));

}

}

TOP COMPANIES HIRING DRIVE

BATCHWISE OFF-CAMPUS DRIVES

1. TCS OFF-CAMPUS DRIVES1. 2018 BATCH
2. INFOSYS OFF-CAMPUS DRIVES2. 2019 BATCH
3. COGNIZANT OFF-CAMPUS DRIVES3. 2020 BATCH
4. WIPRO OFF-CAMPUS DRIVES4. 2021 BATCH
5. CAPGEMINI OFF-CAMPUS DRIVES5. 2022 BATCH

 

To Stay Up-to-date, Follow us on Social Media:


1.      Join our Telegram Channel:

Click Here

2.      Like us on Facebook:

Click Here

3.      Follow us on Instagram:

Click Here

4.      Follow us on LinkedIn:

Click Here

5.      Follow us on Google News:

Click Here

 

ADAPT Different Coding Solutions:


  1. Largest Array Solution – Click Here
  2. Batsman & Bowler Solution – Click Here
  3. Instruments Problem Solution – Click Here
  4. Check Two Person Are Same – Click Here
  5. Medicine App ADAPT Solution – Click Here
  6. String Combination Capgemini ADAPT Solution – Click Here
  7. Remove”X”inString Problem Solution – Click Here

Capgemini ADAPT Sprint 1 (Bus Reservation Solutions):


Capgemini ADAPT Sprint 2 (Bus Reservation System):


Study Materials for Interview Preparation (FREE MATERIALS):


  1. 240 Core Java Questions & Answers with PDF Download Link – Click Here
  2. 230+ SQL interview questions & answers pdf download – Click Here
  3. 50 LeetCode Interview Questions with Answers – PDF Notes – Click Here