I have asked 2 problems yesterday in an interview
1> Given a string, calculate a new string where the corresponding characters in the original letter are different from each other by a "*"
The example is as shown below: :: Function Name 2> Given a string, calculate a new string where all lowercase 'x' characters have been moved to the end of the string. Example: The name of the function: I'm not sure how to complete the given set of problems and how it is struggling to solve. for 1), here is a very simple rezox path: Print: explanation: I later 2) but I do not like many questions wrapped in one. OK because I'm here in a reggae mood 2): changes with public string pair starter string
pairStar ("hello") A ???? "Hello lo couple" ("xx") ??? "X * xy * y" partner ("AAAA") ??? "A * a * a * a"
public string endx (string str)
endX ("xxre" ) a???? "Rex" end X ("xxhixx") ??? "Hixxxx" AndX ("Xhiksha") ??? "Hihixxx"
string in = "hello goodbye"; String out = in.replaceAll ("(.) (? = \\ 1)", "$ 1 *"); Println (outside);
hello * l go to * odbye
(.) // matches any one letter for group 1 (? = \\ 1), that character for 1 $ 1 * / Code>
Edit
string in = "xhix"; String out = in; While (! Out.matches ("[^ x] * x *")) {out = out.replaceAll ("x (. *)", "$ 1x"); } System.out.println (outside); It
x (some) to
(some) x until all
x I did not end the string, though I'm sure that with regex / there is a better way of doing this one.
Comments
Post a Comment