Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4234eac

Browse files
check Palindrome using recursion
1 parent 1ff7cfb commit 4234eac

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.learn.datastructure;
2+
3+
import java.util.*;
4+
5+
public class Palindrome {
6+
public static void main(String args[]) {
7+
Scanner sc = new Scanner(System.in);
8+
int num[] = new int[5];
9+
for(int i=0; i< 5;i++)
10+
num[i]=sc.nextInt();
11+
boolean answer =palindrome(num, 0);
12+
System.out.println(answer);
13+
}
14+
public static boolean palindrome(int[] num, int index) {
15+
if (index > num.length/ 2)
16+
return true;
17+
if (num[index] == num[num.length - index - 1])
18+
return palindrome(num, index + 1);
19+
else
20+
return false;
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /