Last active
August 29, 2015 14:02
-
-
Save jyhjuzi/dc69612f9ef6be06b224 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Q1_4 { | |
public static void main(String args[]){ | |
char[] test = {'a',' ','b',' ',' ','c',' ',' ',' ',' ',' ',' '}; | |
System.out.println(process(test,6)); | |
} | |
static String process(char[] array, int length){ | |
int numberOfSpace = 0; | |
for(int i = 0; i<length; i++){ | |
if(array[i] == ' ') | |
numberOfSpace++; | |
} | |
int retLength = length + 2*numberOfSpace; | |
int j = length-1; | |
for(int i = retLength-1; i>=0; ){ | |
if(array[j] == ' '){ | |
array[i]='0'; | |
array[i-1]='2'; | |
array[i-2] ='%'; | |
i = i-3; | |
} | |
else{ | |
array[i] = array[j]; | |
i--; | |
} | |
j--; | |
} | |
return new String(array); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment