-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment68_.java
More file actions
41 lines (26 loc) · 1.02 KB
/
Assignment68_.java
File metadata and controls
41 lines (26 loc) · 1.02 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
package abhilash_Asignments;
//WAP to check if the given string is palindrome
public class Assignment68_ {
public static void main(String[] args)
{
String Name = "Malayalam";
System.out.println(Name); // not required, but it's fine if you want to print the original string
String n1 = Name.toLowerCase(); // converting the string to lowercase for uniformity
System.out.println(n1); // printing the lowercase string
String reverse = "";
for (int i = n1.length() - 1; i >= 0; i--) { // iterating over the string in reverse order
char r1 = n1.charAt(i); //this is for chartype rversing
reverse = reverse + r1;
}
System.out.println(reverse); // printing the reversed string
boolean results = n1.equals(reverse); // checking if the string is a palindrome
System.out.println(results); // printing the result of the palindrome check
if (results) //if else statement
{
System.out.println("string is palindrome");
} else
{
System.out.println("string is not palindrome");
}
}
}