forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPairStar.java
More file actions
34 lines (28 loc) · 800 Bytes
/
PairStar.java
File metadata and controls
34 lines (28 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class runner {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String input = s.nextLine();
System.out.println(solution.addStars(input));
}
}
public class solution {
// Return the updated string
public static String addStars(String s) {
if(s.length()==1){
return s;
}
char arr1[]=s.toCharArray();
char arr2[]=new char[arr1.length-1];
for(int index=0;index<arr1.length-1;index++){
arr2[index]=arr1[index];
}
String temp2=new String(arr2);
String actual=addStars(temp2);
String s3=Character.toString(arr1[arr1.length-1]);
if(actual.charAt(actual.length()-1)==arr1[arr1.length-1]){
return actual+"*"+s3;
}
return actual+s3;
}
}