How to check Palindrome Number || Basic Programming Questions Series

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 39

  • @guddipatel9506
    @guddipatel9506 5 ปีที่แล้ว +3

    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

    • @shwetankmishra4531
      @shwetankmishra4531 4 ปีที่แล้ว +1

      negative numbers are not palindrome number

  • @19863960
    @19863960 5 ปีที่แล้ว +2

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

  • @luckylily9561
    @luckylily9561 5 ปีที่แล้ว +3

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

  • @sumitsaha9782
    @sumitsaha9782 2 ปีที่แล้ว

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

  • @yolwasmirzat
    @yolwasmirzat 5 ปีที่แล้ว +1

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

  • @abraham2961
    @abraham2961 5 ปีที่แล้ว +3

    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();
    int length = original.length();
    for (int i = length - 1; i >= 0; i--)
    reverse = reverse +original.charAt(i);
    if (original.equals(reverse))
    System.out.println("The string is a palindrome.");
    else
    System.out.println("The string isn't a palindrome.");
    }

  • @anushaka2171
    @anushaka2171 5 ปีที่แล้ว +5

    public static void StringRev(String string){
    String t;
    t=string;
    StringBuffer reversestring = new StringBuffer(String.valueOf(string)).reverse();
    System.out.println(reversestring);
    if(t.contentEquals(reversestring)) {
    System.out.println("It is a PALINDROME");
    }
    else {
    System.out.println("It is NOT a PALINDROME");
    }

    • @naveenautomationlabs
      @naveenautomationlabs  5 ปีที่แล้ว +2

      Good one.

    • @sarojjha9243
      @sarojjha9243 4 ปีที่แล้ว +1

      Not working, it reaches all-time to else part and displaying not a palindrome.Someone please check the code

    • @AmanSaxena-qk9tm
      @AmanSaxena-qk9tm 4 ปีที่แล้ว

      @@sarojjha9243 A bit optimized code with less var :
      public static void RevString(String str) {
      StringBuilder rev = new StringBuilder(str).reverse();
      if (str.contentEquals(rev))
      System.out.println(str + " is Palindrome String.");
      else
      System.out.println(str + " is not Palindrome String.");
      }

  • @20_SinManya
    @20_SinManya 5 ปีที่แล้ว +1

    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.

  • @ramkumarreddy6775
    @ramkumarreddy6775 5 ปีที่แล้ว +1

    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");
    }
    }

  • @kapilrana2361
    @kapilrana2361 5 ปีที่แล้ว

    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");
    }
    }
    }

  • @maafaque9842
    @maafaque9842 2 ปีที่แล้ว

    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=reverseString+name.charAt(i);
    System.out.println(reverseString);
    }
    System.out.println("Reversed: "+reverseString);

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

  • @tejastoley6714
    @tejastoley6714 5 ปีที่แล้ว

    StringBuffer sb = new StringBuffer("Tejas");
    sb.append("Toley");
    system.out.println(sb.reverse);

  • @abraham2961
    @abraham2961 5 ปีที่แล้ว +1

    Hi thanks for this programming

  • @shwetapandey8321
    @shwetapandey8321 3 ปีที่แล้ว

    i tried this code this is also working
    public static void checkPalindrom(int x) {
    int num = x;

    ArrayList arr=new ArrayList();


    while(num>0) {

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

  • @abineshm9695
    @abineshm9695 4 ปีที่แล้ว

    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

  • @Kalaiarasan_Balu
    @Kalaiarasan_Balu 5 ปีที่แล้ว +1

    V expect more program videos

  • @shankarpk89
    @shankarpk89 5 ปีที่แล้ว

    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) == str.toUpperCase().charAt(length - i - 1)) {
    flag++;
    }
    }
    }
    else {
    for (int i = 0; i < (int) (length / 2); i++) {
    if (str.toUpperCase().charAt(i) == str.toUpperCase().charAt(length - 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");
    }
    }
    }

  • @bheemshankar_pk
    @bheemshankar_pk 4 ปีที่แล้ว

    Great tutor

  • @raghuveermh6869
    @raghuveermh6869 5 ปีที่แล้ว

    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...

  • @srinivasmuddappa9663
    @srinivasmuddappa9663 5 ปีที่แล้ว

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

  • @aniruddhadey5889
    @aniruddhadey5889 5 ปีที่แล้ว +1

    Thanks

  • @asheshrastogi2389
    @asheshrastogi2389 2 ปีที่แล้ว

    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"));
    System.out.println("'selenium' is a Palindrome: " + isPalindrome("selenium"));
    System.out.println("'level' is a Palindrome: " + isPalindrome("level"));
    }
    }

  • @renukachavan7442
    @renukachavan7442 5 ปีที่แล้ว

    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 StringBuffer(s).reverse().toString();

    // 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 ");
    }
    }

  • @standwithtruth2194
    @standwithtruth2194 5 ปีที่แล้ว +1

    String malayalam

  • @WMohanty
    @WMohanty 3 ปีที่แล้ว

    How to remember the logic man

  • @shyamchristypaul1058
    @shyamchristypaul1058 4 ปีที่แล้ว

    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);
    }
    //System.out.println(str2);
    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();
    obj.isPalindromString("teet");
    }
    }

  • @abraham2961
    @abraham2961 5 ปีที่แล้ว

    String pop

  • @purushottamw
    @purushottamw 4 ปีที่แล้ว

    //String Reverse
    //String palindrome check
    //Case sensitive handle
    public class StringReverse {
    public static void main(String[] args) {
    ReverseString("kuuk");
    }
    public static void ReverseString(String string) {

    string=string.toUpperCase();
    String rev="";

    //System.out.println(string.length());
    //System.out.println(string);

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

    System.out.println("Reverse String is :"+rev);

    if(string.equals(rev)) {
    System.out.println("String is Palindrome: "+rev);
    }
    else {
    System.out.println("String is not palindrome: "+rev);
    }

    }

  • @myamazingvideos
    @myamazingvideos 5 ปีที่แล้ว

    package introduction;
    public class PalindromeCheck {
    public static void main(String[] args) {
    String input = "nitin";
    int i = input.length();
    char[] ar = input.toCharArray();
    boolean b = isPallindrom(i, ar);
    if (b==true) {
    System.out.println("Mr. Saksham Bahati, The number youve entered is pallidrome");
    }
    else {
    System.out.println("Mr. Saksham Bahati The number you've entered is not pallindrome");
    }
    }
    public static boolean isPallindrom(int length, char y[]) {
    int j = length - 1;
    for (int i = 0; i < length/2; i++) {
    if (y[j]==y[i]) {
    j--;
    }
    else {
    return false;
    }
    }
    return true;
    }
    }
    Thanks @naveen

  • @standwithtruth2194
    @standwithtruth2194 5 ปีที่แล้ว +1

    Thanks