logo

CuriousTab

CuriousTab

Discussion


Home Interview Technology Comments

  • Question
  • Write a method to fill all the spaces in a string with '%20'


  • Correct Answer
  • public class Test { public void replaseSpaces(char[] str, int length) { int spaceCount = 0, newLength = 0, i = 0; for(i = 0; i < length; i++) { if (str[i] == ' ') spaceCount++; } newLength = length + (spaceCount * 2); str[newLength] = '\0'; for(i = length - 1; i >= 0; i--) { if (str[i] == ' ') { str[newLength - 1] = '0'; str[newLength - 2] = '2'; str[newLength - 3] = '%'; newLength = newLength - 3; } else { str[newLength - 1] = str[i]; newLength = newLength - 1; } } Systemoutprintln(str); } public static void main(String[] args) { Test tst = new Test(); char[] ch = {'t', 'h', 'e', ' ', 'd', 'o', 'g', ' ', ' ', ' ', ' ', ' ', ' '}; int length = 6; tstreplaseSpaces(ch, length); } } 


  • Technology problems


    Search Results


    • 1. How would you reverse a doubly-linked list?
    • Discuss
    • 2. Write an algorithm to separate all ones & zeroes in an array.
    • Discuss
    • 3. Define stored procedure. What are its advantages and disadvantages?
    • Discuss
    • 4. What are the different types of system calls?
    • Discuss
    • 5. What exactly do you mean by UDP?
    • Discuss
    • 6. Difference between system call and API
    • Discuss
    • 7. What is Marshalling?
    • Discuss
    • 8. How do you handle errors in CICS programs?
    • Discuss
    • 9. How can you have different number of cells for each row of a table?
    • Discuss
    • 10. What is IUnknown and what are its three parts?
    • Discuss


    Comments

    There are no comments.

Enter a new Comment