forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrom_Number.java
More file actions
36 lines (33 loc) · 856 Bytes
/
Palindrom_Number.java
File metadata and controls
36 lines (33 loc) · 856 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
package com;
import java.util.Scanner;
public class Palindrom_Number {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
System.out.println("Enter string to check it is PALINDROME or not= ");
String s1 = s.nextLine();
s.close();
/*
* int sum = 0; int a,flag; flag=n;
*
* while(n>0){
*
* a=n%10; sum=(sum*10)+a; n=n/10; } if(flag==sum){ System.out.println(sum + " "
* + "is palindrome number "); }else{ System.out.println(sum + " " +
* "isnot palindrome number"); } }
*/
String rev = "";
int l = s1.length();
for (int i = l - 1; i >= 0; i--) {
rev = rev + s1.charAt(i);
}
if (s1.equals(rev)) {
System.out.println(s1 + " is a Palindrome");
} else {
System.out.println(s1 + " is not a Palindrome");
}
}
}