-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalW.java
More file actions
31 lines (25 loc) · 705 Bytes
/
Copy pathpalW.java
File metadata and controls
31 lines (25 loc) · 705 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
package E3;
import java.util.Scanner;
public class palW {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Insert the string to be checked");
String s = sc.nextLine();
boolean isPalindrome = true;
int i = 0;
while (i <= s.length() - 1 && isPalindrome == true) {
char c1 = s.charAt(i);
int j = s.length() - 1 - i;
char c2 = s.charAt(j);
if (c1 != c2)
isPalindrome =
false;
i++;
}//while
if (isPalindrome == true)
System.out.println("The string is palindrome");
else
System.out.println("The string is not palindrome");
}//main
}//class PalindromeUsingWHILE