FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/Other-Java-Programs/RemoveWordFromString.java at master · iamarav/Java-Programs · GitHub
iamarav
/
Java-Programs
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
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-Programs
/
Other-Java-Programs
/
RemoveWordFromString.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
82 lines (63 loc) · 2.15 KB
Breadcrumbs
Java-Programs
/
Other-Java-Programs
/
RemoveWordFromString.java
Copy path
File metadata and controls
82 lines (63 loc) · 2.15 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import
java
.
util
.
Scanner
;
public
class
RemoveWordFromString
{
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
"Program to remove a word from String.
\n
---"
);
String
string
=
""
,
word
=
""
;
Scanner
sm
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Enter the String: "
);
string
=
sm
.
nextLine
();
System
.
out
.
print
(
"Enter the word to remove from String: "
);
word
=
sm
.
nextLine
();
if
(
string
.
isEmpty
() ||
string
.
equals
(
" "
)) {
//To check if String is empty.
System
.
out
.
println
(
"The String is empty"
);
end
();
}
else
if
(
word
.
isEmpty
() ||
word
.
equals
(
" "
)) {
//To check if word is empty.
System
.
out
.
println
(
"The Word entered is blank."
);
end
();
}
if
(
removeWord
(
string
,
word
)) {
end
();
}
sm
.
close
();
}
private
static
boolean
removeWord
(
String
string
,
String
word
) {
boolean
bb
=
true
;
if
(
checkWord
(
string
,
" "
+
word
)) {
//for words between Strings
//Now Remove the word from String//
string
=
string
.
replaceAll
(
" "
+
word
,
""
);
System
.
out
.
println
(
"Word has been removed from String."
);
System
.
out
.
println
(
"Output String: "
+
string
);
}
else
if
(
checkWord
(
string
,
word
+
" "
)) {
//for words at the starting of string
//Now Remove the word from String//
string
=
string
.
replaceAll
(
word
+
" "
,
""
);
System
.
out
.
println
(
"Word has been removed from String."
);
System
.
out
.
println
(
"Output String: "
+
string
);
}
else
if
(
checkWord
(
string
,
word
)) {
//for words at the end of string
//Now Remove the word from String//
string
=
string
.
replaceAll
(
word
,
""
);
System
.
out
.
println
(
"Word has been removed from String."
);
System
.
out
.
println
(
"Output String: "
+
string
);
}
else
{
System
.
out
.
println
(
"Word not found in String"
);
System
.
out
.
println
(
"Output String: "
+
string
);
end
();
}
return
bb
;
}
private
static
boolean
checkWord
(
String
string
,
String
word
) {
//Function to check if word exist in String
boolean
flag
=
false
;
if
(
string
.
contains
(
word
)) {
System
.
out
.
println
(
"Word found in String"
);
flag
=
true
;
}
return
flag
;
}
private
static
void
end
() {
//Function to end Program
System
.
out
.
println
(
"---
\n
The Program has ended."
);
System
.
exit
(
0
);
}
}
Back
|
FazBrowse Home
|
New Git URL