I recently attaneded the interview at Mvi Technology. there i got some new Questions. in this blog i just share my questiions and asnwers in my next blogs i will share my experince on the interviews.
before move into the question gernral instruction
dont use any inbuil methods u can only use the length() and charAt() only. 4 questions only 60 minutes time.
Question - 1
- input String s = "ABC124ABC1WEWE"; the output should be like this CBA124CBA1EWEW revers only the string dont reverse the numbers and this should stayed on the plce where it already presents.
public class Four {
public static void main(String[] args) {
String s = "ABC124ABC1WEWE";
int start = 0, end = 0;
String s1 = "";
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')) {
end++;
} else {
if (end != start) {
s1 += rev(s, start, end);
}
s1 += s.charAt(i);
start = i + 1;
end = start;
}
}
if (end != start) {
s1 += rev(s, start, end);
}
System.out.println(s1);
}
public static String rev(String s, int st, int e) {
String s2 = "";
for (int i = e - 1; i >= st; i--) {
s2 += s.charAt(i);
}
return s2;
}
}
output : CBA124CBA1EWEW
Top comments (0)