FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/Anagram.java at master · AmanKansal2012/Java-Programs · GitHub
AmanKansal2012
/
Java-Programs
Public
forked from
codec-akash/DSA-PS-Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
Anagram.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (46 loc) · 1.32 KB
Breadcrumbs
Java-Programs
/
Anagram.java
Copy path
File metadata and controls
50 lines (46 loc) · 1.32 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
import
java
.
util
.
Scanner
;
/*This java program is used to find whether the strings are is anagram(An anagram is a word or phrase
* formed by rearranging the letters of a different word or phrase, typically
* using all the original letters exactly once) of each other or not or not.*/
public
class
Anagram
{
public
static
void
main
(
String
[]
args
) {
// TODO Auto-generated method stub
Scanner
sc
=
new
Scanner
(
System
.
in
);
String
a
=
sc
.
nextLine
();
String
b
=
sc
.
nextLine
();
if
(
a
.
length
()!=
b
.
length
())
{
System
.
out
.
println
(
"Not Anagram"
);
}
else
{
boolean
flag
=
true
;
int
arr
[]=
new
int
[
256
];
/*Storing Number of characters of string a in array according to ASCII values*/
for
(
char
e
:
a
.
toCharArray
())
{
arr
[(
int
)
e
]++;
}
/*Storing Number of characters of string b in array according to ASCII values*/
for
(
char
e
:
b
.
toCharArray
())
{
arr
[(
int
)
e
]--;
}
/*Comparing the arrays to find whether the characters are same or not in both strings*/
for
(
int
i
=
0
;
i
<
256
;
i
++)
{
if
(
arr
[
i
]!=
0
)
{
flag
=
false
;
}
}
if
(!
flag
)
{
System
.
out
.
println
(
"Not Anagram"
);
}
else
System
.
out
.
println
(
"Anagram"
);
}
sc
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL