-
-
Save asdw3276/bcac142e15ec2b9193e1 to your computer and use it in GitHub Desktop.
1.4
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 replacespace{ | |
public static void main(String[] args) | |
{ | |
String teststring = "Mr John Smith sdfsf sdfs sssf d s"; | |
char[] testchar = teststring.toCharArray(); | |
char[] imput = new char[100]; | |
for(int i = 0; i < testchar.length; i++) | |
imput[i] = testchar[i]; | |
char[] result = replacespace(imput,testchar.length); | |
System.out.println(String.valueOf(result)); | |
} | |
public static char[] replacespace(char[] imput,int length) | |
{ | |
int count = 0; | |
for(int i = 0; i < imput.length; i++) | |
{ | |
if(imput[i] == ' ') | |
{ | |
count++; | |
} | |
} | |
for(int i = length; i >= 0; i--) | |
{ | |
if(imput[i] == ' ') | |
{ | |
imput[i + count * 2] = '0'; | |
imput[i + count * 2 - 1] = '2'; | |
imput[i + count * 2 - 2] = '%'; | |
count--; | |
} | |
else | |
imput[i+count*2] = imput[i]; | |
} | |
return imput; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment