forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome_nomit.java
More file actions
33 lines (28 loc) · 874 Bytes
/
Palindrome_nomit.java
File metadata and controls
33 lines (28 loc) · 874 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
/*
* @author Nomit Pahuja
* date: 29/01/2019
*/
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the String: ");
String word = input.next();
word = word.toLowerCase();
int size = word.length();
int flag = 1;
//checking if string is palindrome or not
for(int i = 0, j = size-1; i<size/2; i++, j--){
if(word.charAt(i) != word.charAt(j)){
flag = 0;
}
}
//print if string is palindrome or not
if(flag == 0){
System.out.println("The given string is not a palindrome.");
} else {
System.out.println("The given string is a palindrome.");
}
input.close();
}
}