## Oracle Interview Question

Software Engineer / Developerspublic String replace(String txt){

int sp= 0;

char [] chs = txt.toCharArray();

for (int i =0 ;i<chs.length ;++i){

if (chs[i] ==' '){

sp++;

}

}

char [] n_ch = new char [txt.length()+sp*2];

int j =0;

for (int i = 0 ;i<chs.length ;++i){

if (chs[i]==' '){

n_ch[j] = '%';

n_ch[j+1] = '2';

n_ch[j+2] = '0';

j+=3;

}else{

n_ch[j++] = chs [i] ;

}

}

return new String(n_ch);

}

#include<iostream>

#include<stdlib.h>

using namespace std;

int main()

{

char myString[] = "Mrs. Vathsala Nagaraju ";

cout << endl << myString;

int n, k, i, x;

n = k = strlen(myString);

cout << endl << "value of k and n are " << k << " and " << n;

k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)

{

if (myString[i] != ' ')

{

while (myString[i] != ' ')

{

myString[i + k] = myString[i];

i = i - 1;

}

k = k - 2;

myString[i+k] = '%';

myString[i+k+1] = '2';

myString[i+k+2] = '0';

}

}

cout << endl << myString;

cin >> x;

return 0;

}

#include<iostream>

#include<stdlib.h>

using namespace std;

int main()

{

char myString[] = "Mrs. Vathsala Nagaraju ";

cout << endl << myString;

int n, k, i, x;

n = k = strlen(myString);

cout << endl << "value of k and n are " << k << " and " << n;

k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)

{

if (myString[i] != ' ')

{

while (myString[i] != ' ')

{

myString[i + k] = myString[i];

i = i - 1;

}

k = k - 2;

myString[i+k] = '%';

myString[i+k+1] = '2';

myString[i+k+2] = '0';

}

}

cout << endl << myString;

cin >> x;

return 0;

}

#include<iostream>

#include<stdlib.h>

using namespace std;

int main()

{

char myString[] = "Mrs. Vathsala Nagaraju ";

cout << endl << myString;

int n, k, i, x;

n = k = strlen(myString);

cout << endl << "value of k and n are " << k << " and " << n;

k = n = n - 1;

while (myString[n] == ' ') n = n - 1;

k = k - n;

for (i = n; i > 0; i--)

{

if (myString[i] != ' ')

{

while (myString[i] != ' ')

{

myString[i + k] = myString[i];

i = i - 1;

}

k = k - 2;

myString[i+k] = '%';

myString[i+k+1] = '2';

myString[i+k+2] = '0';

}

}

cout << endl << myString;

cin >> x;

return 0;

}

```
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
char myString[] = "Mrs. Vathsala Nagaraju ";
cout << endl << myString;
int n, k, i, x;
n = k = strlen(myString);
cout << endl << "value of k and n are " << k << " and " << n;
k = n = n - 1;
while (myString[n] == ' ') n = n - 1;
k = k - n;
for (i = n; i > 0; i--)
{
if (myString[i] != ' ')
{
while (myString[i] != ' ')
{
myString[i + k] = myString[i];
i = i - 1;
}
k = k - 2;
myString[i+k] = '%';
myString[i+k+1] = '2';
myString[i+k+2] = '0';
}
}
cout << endl << myString;
cin >> x;
return 0;
}
```

```
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
char myString[] = "Mrs. Vathsala Nagaraju ";
cout << endl << myString;
int n, k, i, x;
n = k = strlen(myString);
cout << endl << "value of k and n are " << k << " and " << n;
k = n = n - 1;
while (myString[n] == ' ') n = n - 1;
k = k - n;
for (i = n; i > 0; i--)
{
if (myString[i] != ' ')
{
while (myString[i] != ' ')
{
myString[i + k] = myString[i];
i = i - 1;
}
k = k - 2;
myString[i+k] = '%';
myString[i+k+1] = '2';
myString[i+k+2] = '0';
}
}
cout << endl << myString;
cin >> x;
return 0;
```

}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> January 25, 2014