Given a string, return a string made of the first two characters (if present), however include the first character only if it is 'o' and include the second only if it is 'z', so "ozymandias" yields "oz".
is the question I'm trying to solve. I can't change characters to be empty strings. I know the code is messy, but I'm trying to find out how to make the characters empty strings without using null character, Unicode, or min_value, etc. How do I do it?
public String startOz(String str) {
char a = ' ';
char b = ' ';
String c = "";
String d ="";
if(str.length() <= 1){
if(str.length() == 0){
return "";
}
else
if(str.charAt(0) == 'o'){
return str;
}
else;
return "";
}
else{
if(str.charAt(0) == 'o'){
a = 'o';
c = Character.toString(a);
}
else;
c = Character.toString(a);
c = c.substring(1);
if(str.charAt(1) == 'z'){
b = 'z';
d = Character.toString(b);
}
else;
d = Character.toString(b);
d = d.substring(1);
c = Character.toString(a);
d = Character.toString(b);
return c + d;
}
}