PairStar in java

PairStar in Java

Given a string, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a “*”.

pairStar(“hello”) → “hello” pairStar(“xxyy”) → “xxyy” pairStar(“aaaa”) → “aaaa”

** Input format** The first line contains the string.

Output format Print the desired output where there is a * between consecutive same characters.

Example hello Output hel*lo

Constraints 1 <= Len(str) <= 1000

Solution of PairStar:–

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(;
  public static String pairstar(String s)
      return s;
      return s.charAt(0)+"*"+pairstar(s.substring(1));

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

Add a Comment

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