noX in java

noX in java

Given a string, compute recursively a new string where all the ‘x’ chars have been removed.

noX(“xaxb”) → “ab” noX(“abc”) → “abc” noX(“xx”) → “”

** Input Format ** Only line contains the string S.

Output Format Print the string with no X.

Example xaaax Output aaa

Solution of noX in java:–

import java.util.*;
import java.lang.*;

public class Main
	public static void main (String[] args) throws java.lang.Exception
		//your code here
      Scanner sc=new Scanner(;
      String s=sc.nextLine();
  public static String nox(String s)
      return " ";

    if(s.charAt(0)=='x' || s.charAt(0)=='X')
      return nox(s.substring(1));

        return s.charAt(0)+nox(s.substring(1));

Add a Comment

Your email address will not be published. Required fields are marked *