Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
56 lines (47 loc) · 1.46 KB

File metadata and controls

56 lines (47 loc) · 1.46 KB
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
import java.util.Scanner;
public class Solution {
static boolean isAnagram(String a, String b){
//set string to lowerCase
a = a.toLowerCase();
b = b.toLowerCase();
//place into char Arrays
char[] charA = a.toCharArray();
char[] charB = b.toCharArray();
//return false if length differs
if (charA.length != charB.length){
return false;
}
else {
//sort alphabetical
for (int i = 0; i < charA.length; i++) {
for (int j = 0; j < charA.length; j++) {
if (charA[i] < charA[j]){
swapChars(charA, i, j);
}
if(charB[i] < charB[j]){
swapChars(charB, i, j);
}
}
}
for (int i = 0; i < charA.length; i++) {
if(charA[i] != charB[i]){
return false;
}
}
}
return true;
}
static void swapChars(char[] charA, int i, int j) {
char temp = charA[i];
charA[i] = charA[j];
charA[j] = temp;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a = scan.next();
String b = scan.next();
scan.close();
boolean ret = isAnagram(a, b);
System.out.println( (ret) ? "Anagrams" : "Not Anagrams" );
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.