-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.java
More file actions
36 lines (34 loc) · 964 Bytes
/
Palindrome.java
File metadata and controls
36 lines (34 loc) · 964 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
//Program to check whether string is palindrome or not
import java.util.Scanner;
class CheckPalindrome{
int check(String userString){
int j = userString.length()-1;
for(int i=0;i<userString.length();i++){
if(userString.charAt(i)==userString.charAt(j)){
j--;
continue;
}
else{
return -1;
}
}
return 0;
}
}
// driver code
public class Palindrome{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String userString = sc.nextLine();
CheckPalindrome obj1 = new CheckPalindrome();
obj1.check(userString);
if(obj1.check(userString)==0){
System.out.println("string is palindrome");
}
else{
System.out.println("String is not palindrome");
}
sc.close();
}
}