-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome.java
More file actions
40 lines (34 loc) · 935 Bytes
/
Copy pathpalindrome.java
File metadata and controls
40 lines (34 loc) · 935 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
37
38
39
40
/*
* File : palindrome.java
* Description : chech whether a no. is palindrome
* Author : Alene Elsa
* Version : 1.0
* Date : 29/09/23
*/
import java.util.Scanner;
public class palindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String input=sc.next();
boolean ispalindrome=check(input);
if (ispalindrome) {
System.out.println("the given string is palindrome");
}
else {
System.out.println("the given string is not palindrome");
}
}
/*function receives string as input
* return true if it is palindrome else false
*/
static boolean check(String input) {
char[]charArray=input.toCharArray();
int length=input.length();
for(int i=0;i<length/2;i++) {
if(charArray[i]!=charArray[length-i-1]) {
return false;
}
}
return true;
}
}