FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-algorithims/InsertString.java at main · faraimtb/java-algorithims · GitHub
This repository was archived by the owner on Dec 7, 2024. It is now read-only.
faraimtb
/
java-algorithims
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-algorithims
/
InsertString.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (48 loc) · 1.52 KB
Breadcrumbs
java-algorithims
/
InsertString.java
Copy path
File metadata and controls
56 lines (48 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package
com
.
ematrix
;
public
class
InsertString
{
public
String
transformString
(
char
[]
S
){
StringBuilder
result
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
S
.
length
;
i
++){
if
(
S
[
i
] ==
' '
)
{
result
.
append
(
"%20"
);
continue
;
}
result
.
append
(
S
[
i
]);
}
return
result
.
toString
();
}
public
void
transformStringTwo
(
char
[]
str
,
int
truelength
){
int
spaceCount
=
0
;
int
index
;
int
i
=
0
;
for
(
i
=
0
;
i
<
truelength
;
i
++){
if
(
str
[
i
] ==
' '
)
{
spaceCount
++;
continue
;
}
}
index
=
truelength
+
spaceCount
*
2
;
if
(
truelength
<
str
.
length
)
str
[
truelength
]=
'\0'
;
for
(
i
=
truelength
-
1
;
i
>=
0
;
i
-- ) {
if
(
str
[
i
] ==
' '
) {
str
[
index
-
1
] =
'0'
;
str
[
index
-
2
] =
'2'
;
str
[
index
-
3
] =
'%'
;
index
=
index
-
3
;
}
else
{
str
[
index
-
1
] =
str
[
i
];
index
--;
}
}
}
public
static
void
main
(
String
[]
args
){
char
[]
str
=
"Mr John Smith "
.
toCharArray
();
InsertString
insertString
=
new
InsertString
();
String
result
=
insertString
.
transformString
(
"Mr John Smith"
.
toCharArray
());
insertString
.
transformStringTwo
(
str
,
13
);
for
(
int
i
=
0
;
i
<
str
.
length
;
i
++)
System
.
out
.
print
(
str
[
i
]);
}
}
Back
|
FazBrowse Home
|
New Git URL