How to check Palindrome Number || Basic Programming Questions Series

preview_player
Показать описание
In this video, we will learn how to write a program to check the given number is Palindrome or not.

Learn:
1. check the given number is Palindrome or not.
2. write different test cases

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

WebServices API Automation Tutorials:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Paid courses (Recorded) videos:
📗 Get My Paid Courses at
Paid courses (Recorded) videos:
-------------------------------

✔️SOCIAL NETWORKS
--------------------------------

Support My Channel✔️Or Buy Me A Coffee
--------------------------------
✔️Thanks for watching!
देखने के लिए धन्यवाद
Благодаря за гледането
感谢您观看
Merci d'avoir regardé
Grazie per la visione
Gracias por ver
شكرا للمشاهدة
Рекомендации по теме
Комментарии
Автор

Great Tutorial but your program won't work if the given number is Negative, for eg: -121 or so....so in a while loop instead of (num > 0) use while(num != 0) and it will work for all the test cases

guddipatel
Автор

private boolean isPalindrome(String str) {
String revStr = new //can also use StringBuilder instead of StringBuffer
return
}

sumitsaha
Автор

Thank you... U thought nicely.. Can u make more videos of stings, arrays, nd patterns..

luckylily
Автор

sir i hope would u complete programming video series at least 50-60 program mainly from string & array

Автор

Palindrome String program:
public class PalindromeString {

public static void isPalindromeString(String name) {
String rev = " ";
int length = name.length();
for (int i = length - 1; i >= 0; i--) {
rev = rev + name.charAt(i);
}
System.out.println("The reverse of the name - " + rev);
if (rev.equals(name)) {
System.out.println(rev+ " - is a polindrome");
} else
System.out.println(rev+ " - not a polindrome");

}

public static void main(String[] args) {
isPolindromeString("MADAM");
isPolindromeString("Madam");

}
}

ramkumarreddy
Автор

public static void isPalindromeString(String name) {
String original=name;
int length=name.length();
String reverseString="";
System.out.println("Lenght of String:"+length);
for(int i=length-1;i>=0;i--) {


}
"+reverseString);

{
System.out.println("Its a Palindrom String");
} else {
System.out.println("Not a Palindrom String");
}
}

maafaque
Автор

Hi Naveen, Just wanted to know, Can we write the above program in below way. Or what an interviewer can say if I give the below answer. Please suggest and let me know what is the issue in this.


public class PalindromeNumber {

public static void main(String[] args)
{

int a = 252;

String b = String.valueOf(a);

StringBuffer sb = new StringBuffer(b);
StringBuffer c = sb.reverse();
String d = c.toString();

if (b.equals(d))
{
System.out.println("the number is palindrome number");
}

else
{
System.out.println("The number is not a palindrome number");
}

}

}

kapilrana
Автор

Without reverse method
String original, reverse = ""; 

      Scanner in = new Scanner(System.in);

     

      System.out.println("Enter a string to check if it is a palindrome");

      original = in.nextLine();

     

   

     

   

       

         

   

         System.out.println("The string is a palindrome.");

      else

         System.out.println("The string isn't a palindrome.");

            }

abraham
Автор

public static void StringRev(String string){
String t;
t=string;


StringBuffer reversestring = new

{
System.out.println("It is a PALINDROME");
}
else {
System.out.println("It is NOT a PALINDROME");
}

anushaka
Автор

I have one doubt: Is '1001' is a palindrome (Note the single quotes before answering)?It would be very nice if you can show the program using strings.

_SinManya
Автор

StringBuffer sb = new StringBuffer("Tejas");
sb.append("Toley");

tejastoley
Автор

An alternate approach - Single program for both integers and strings


package largestNumber;
import java.util.Scanner;
public class Palindrome {


public static int[] checkPalindrome(Object x) {

int flag = 0;

int a[] = new int[2];

String str = String.valueOf(x);

int length = str.length();

if (length % 2 == 0) {

for (int i = 0; i < (length / 2); i++) {

if (str.toUpperCase().charAt(i) == - i - 1)) {

flag++;
}
}

}

else {

for (int i = 0; i < (int) (length / 2); i++) {

if (str.toUpperCase().charAt(i) == - i - 1)) {

flag++;
}
}

}

a[0] = length;
a[1] = flag;

return a;

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("ENTER SOMETHING");

Object x = sc.nextLine();

System.out.println(x);

int[] b = checkPalindrome(x);

if (b[1] == (int) (b[0] / 2)) {

System.out.println(x + " IS A PALINDROME");
}

else {

System.out.println(x + " IS NOT A PALINDROME");
}

}

}

shankarpk
Автор

Hello, if you have time can you please cover Anagram, Duplicate Word, Permutation, Determined Largest Word please, Thank you

yolwasmirzat
Автор

i tried this code this is also working

public static void checkPalindrom(int x) {
int num = x;

ArrayList<Integer> arr=new ArrayList<Integer>();


while(num>0) {

arr.add(num%10);
num=num/10;
}
int c=0;
int i=0;
int j=arr.size()-1;
while(i<arr.size()) {
if(arr.get(i)!=arr.get(j)) {
c=1;

break;
}
i++;
j--;
}
if(c==0) {
System.out.println("this number is a palindrome");
}
else {
System.out.println("this number is not a palindrome");
}
}

shwetapandey
Автор

hi sir, how to write a code to separate number, alphabhaet, special character from a ...
string input = (a24js7f.%^
output =ajsf
247
(.%^
this was asked in recent interview, please explain

abineshm
Автор

Solution for String Palindrome


public static void isPalindrome(String a){


String b = " ";


int n = a.length();


for(int i = n-1; i>=0;i--){
b = b+a.charAt(i);
}


if(a.equalsIgnoreCase(b)){
System.out.Println("The enterd String is Palindrome);
}
else{
System.out.println("The enterd String is not a palindrome");
}
}


Call this into the Main Method and pass the input String...

raghuveermh
Автор

To check if a given String is Palindrome


public class PalindromeString {

public static boolean isPalindrome(String str) {
String rev = "";

for(int i = str.length()-1; i>=0; i--) {
rev = rev+str.charAt(i);
}

if(rev.equals(str)) {
return true;
}
return false;
}

public static void main(String[] args) {
// TODO Auto-generated method stub

System.out.println("'radar' is a Palindrome: " + isPalindrome("radar"));
is a Palindrome: " + isPalindrome("selenium"));
System.out.println("'level' is a Palindrome: " + isPalindrome("level"));
}

}

asheshrastogi
Автор

Program to check if a string is palidrome or not :
public class PalindromeString {

public static void isPalindromeString(String s) {
System.out.println("Given string is :" + s);
// reverse the given String
String reverse = new

// check whether the string is palindrome or not
if (s.equals(reverse)) {
System.out.println("a Palindrome string");
}
else
System.out.println("not a palindrome string");
}

public static void main(String args[])
throws java.lang.Exception

{
isPalindromeString(" madam ");
isPalindromeString(" malayalam ");
isPalindromeString(" renuka ");
isPalindromeString(" abbc ");
}
}

renukachavan
Автор

If we give any palindrome number starting with 0 this logic does not work example 012210

srinivasmuddappa
Автор

public class PalindromeClass {
public void isPalindromString(String str1) {
String str2= "";
int i = str1.length();
for(i =str1.length()-1;i>=0;i--)
{
str2 = str2+str1.charAt(i);
}


if (str1.equals(str2))
{
System.out.println("This is a Palindrome String");
}
else
{
System.out.println("This is not a Palindrome String");
}



}
public static void main(String[] args) {

PalindromeClass obj =new PalindromeClass();


}

}

shyamchristypaul