Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whether Given String is Palindrome using Recursion #184

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions PalindromeUsingRecursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.util.Scanner;

public class PalindromeUsingRecursion {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter the input String :");
String s=sc.nextLine();
boolean res= isPalindrome(s,0,s.length()-1);
if(res)
System.out.println("given String is Palindrome");
else
System.out.println("given String is not a Palindrome");

}
public static boolean isPalindrome(String s,int st,int lt)
{
if(s.charAt(st)!=s.charAt(lt))
return false;
if(st>=lt)
return true;
return isPalindrome(s,st+1,lt-1);
}

}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ It is very easy to contribute, you may follow these steps -
99.[RotateLinkedList](https://github.com/PrajaktaSathe/Java/blob/main/Programs/RotateLinkedList.java)-Program to demo rotating a linked list
100. [ReverseString](https://github.com/PrajaktaSathe/Java/blob/main/ReverseString.java) -Program to reverse a String using the java method substring.
101.[Overriding](https://github.com/PrajaktaSathe/Java/blob/main/Programs/Overriding.java)-Program to demo overriding in java
102. [https://github.com/Venkatesh898/JavaOS/blob/feat/PalindromeUsingrecursion/PalindromeUsingRecursion.java] Java program to check whether a given String is palindrome or not using recursion.

# Contributors -
## A big thank you to all our contributors!!!
Expand Down