-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
52 lines (28 loc) · 974 Bytes
/
Palindrome.java
File metadata and controls
52 lines (28 loc) · 974 Bytes
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
import java.util.Scanner;
public class Palindrome{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a Word: ");
String user_input = input.next();
boolean check = Plaindrome(user_input.toLowerCase());
System.out.println(check);
}
public static boolean Plaindrome(String user_input){
char []arr = new char[user_input.length()];
int flag = 0;
for (int i = 0; i < user_input.length(); i++){
arr[i] = user_input.charAt(user_input.length() - i - 1);
}
for (int j = 0; j < user_input.length(); j++){
if(arr[j] == user_input.charAt(j)){
flag++;
}
}
if(flag == user_input.length()){
return true;
}
else{
return false;
}
}
}