-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
53 lines (45 loc) · 1 KB
/
Palindrome.java
File metadata and controls
53 lines (45 loc) · 1 KB
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
/*
* author : Yu Chenghui
* matric no. : A0194474U
*/
import java.util.*;
public class Palindrome {
/* use this method to check whether the string is palindrome word or not
* PRE-Condition :
* POST-Condition :
*/
public static boolean isPalindrome(String word) {
int length = word.length();
boolean flag = true;
for (int i = 0; i < length / 2; i++) {
if (word.charAt(i) == word.charAt(length - i - 1)) {
continue;
} else {
flag = false;
break;
}
}
return flag;
}
public static void main(String[] args) {
// declare the necessary variables
String str1;
String str2;
String word;
boolean flag;
// declare a Scanner object to read input
Scanner sc = new Scanner(System.in);
// read input and process them accordingly
str1 = sc.nextLine();
str2 = sc.nextLine();
// simulate the problem
word = str1 + str2;
flag = isPalindrome(word);
// output the result
if (flag) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}