Palindrome Program In Java Tutorial #63

Поділитися
Вставка
  • Опубліковано 12 вер 2024

КОМЕНТАРІ • 111

  • @alexlorenlee
    @alexlorenlee  10 місяців тому +3

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @kangdysalltag
    @kangdysalltag 2 роки тому +3

    Hey Alex, I rarely leave comments but I have to say your tutorials are the easiest and coolest way to learn Java! Thank you so much for making these videos. It really helps me a lot to actually gain more interest in programming and not to give up! I love how you make hard things look simple and clear and that really motivates me to keep on going! I also agree on all the comments below that you are amazing! Thanks again!

  • @steveejoel3248
    @steveejoel3248 4 роки тому +7

    Bro honestly you are my go to now you explain things at my level of understanding thanks!

  • @lionson5253
    @lionson5253 5 років тому +7

    Thanks for all these vids!
    I just started learning java and your tutorials are the best out here

    • @alexlorenlee
      @alexlorenlee  5 років тому +3

      that's great to hear, thank you! I'm happy to help

  • @sospylon5848
    @sospylon5848 5 років тому +9

    Good video, maybe in the future you could make a video on program that generates every permutation of an array, i had problems with is lately so i would love to see you explaining it.

  • @thatChillLife2037
    @thatChillLife2037 2 роки тому +2

    I just started learning Java a few months ago and I LOVE your tutorials! They explain things so well and you're right, some people learn better by seeing! I just spent 30 min working with how to create a palindrome method online--I took a break and said, let's give videos a try. SO. MUCH. BETTER! Thanks 🙂

    • @trodg
      @trodg Рік тому

      Hows your coding coming along?

  • @maelstrom57
    @maelstrom57 3 роки тому +2

    public static boolean isPalindrome(String input) {
    String reverseInput = "";
    for (int i = 0; i < input.length(); i++)
    reverseInput = input.charAt(i) + reverseInput;
    if (input.equals(reverseInput))
    return true;
    return false;
    }

  • @CssSpyxed
    @CssSpyxed 2 роки тому +1

    I've been learning programming since 2019 and gave up in 2020. Now I'm back and found this channel a while ago, it goes so much better and faster since that. Thank you, Alex, you're amazing!

  • @baran_2451
    @baran_2451 2 роки тому +2

    Thank you bro👍🏻

  • @shauryagaur1262
    @shauryagaur1262 5 років тому +9

    Hi Alex whats upp
    Though I am a student but still watch your content
    Lots of support from india

  • @lathasridhar5299
    @lathasridhar5299 3 роки тому +4

    Thank you, this is very helpful for interviews! very nicely explained!

  • @negativecreep9971
    @negativecreep9971 3 роки тому +4

    Is it common to see a palindrome problem for the first time, and have no idea how to create a solution?

    • @zububabu8249
      @zububabu8249 9 місяців тому

      Yes if u don't know about 2 pointers

  • @veronicadanu1993
    @veronicadanu1993 4 роки тому +2

    You helped me a lot! Thanks Alex, you do a very good job!

  • @kil9730
    @kil9730 2 роки тому +1

    Wth i understood this so quick man I'm starting from the basics now

  • @edwardmallia22
    @edwardmallia22 5 років тому +2

    Hey Alex I've been watching your vids for a while and I love them. I have a computing project coming up soon that's really important and was wondering if you could do a tutorial on how to use the pop up window and add labels, buttons, lists and stuff like that. Similar to the one of the arrow key detection just with how to use all the different things you can add. Keep up the brilliant work.

  • @heksqer1022
    @heksqer1022 5 років тому +15

    Great video , but couldn't we just compare the strings instead of comparing the characters one by one in a loop ?
    Say if(original.equals(reverse)){ System.out.println("PALINDROME");}

    • @alexlorenlee
      @alexlorenlee  5 років тому +3

      Tiltproof Meepo yes you could do that too :)

  • @ramonsanchez8815
    @ramonsanchez8815 3 роки тому +1

    Great work . Explained every step of the way !! Extremely appreciate it

  • @nerodant85
    @nerodant85 5 років тому +3

    Thank you for the amazing vids Alex, they help a lot.

  • @-------------------299
    @-------------------299 3 роки тому +1

    Very nice video!!

  • @soniafaizabenchebana3128
    @soniafaizabenchebana3128 2 роки тому +1

    you are the best alex please keep up the great work !

  • @aaaaaaaaaaaaahhhhhhhhhhhhhhh
    @aaaaaaaaaaaaahhhhhhhhhhhhhhh 4 роки тому +4

    You're AMAZING!!!

  • @peppermintdior
    @peppermintdior 3 роки тому +1

    YOur videos are great really helping me through college ♥ thanks ALEX

  • @LilyMai0723
    @LilyMai0723 3 роки тому +1

    Thank you Alex you are the best! ♥️

  • @jesussister595
    @jesussister595 4 роки тому +3

    if(reverse.equals(original))
    palindrome = true ;
    why we dont do it like that ? is there something wrong on this?

    • @a.hao97
      @a.hao97 4 роки тому

      Yes i used that, it reduced the complexity of the code and it works fine. I tried to use if ( reverse == original) instead and kept getting error messages until i explored using equals..

  • @VTObi4z
    @VTObi4z 2 роки тому

    U deserve more attention, and many more subscribers! UA-cam should pay you more!

  • @sultanah5541
    @sultanah5541 3 роки тому +1

    thanks man, really helped

  • @ultra_mega_tronic_source
    @ultra_mega_tronic_source 3 роки тому +1

    yow, Alex... thanks, bro... I learn so many things from you...

  • @justinyao2842
    @justinyao2842 Рік тому +1

    bro Alex u should never stop teaching us JAVA

  • @muhammadnusrum6351
    @muhammadnusrum6351 Рік тому

    So well explained, helped me a lot understanding each statement!

  • @ChristianAllertse
    @ChristianAllertse 2 роки тому +1

    at the boolean part, why its says "Unreachable code" how do i fix that?

  • @Ziggy0120
    @Ziggy0120 3 роки тому +1

    I did this similarly but with the stack and queue data structure

  • @unofficialbeastx929
    @unofficialbeastx929 3 роки тому +1

    Thats you really helped!

  • @jharding32
    @jharding32 4 роки тому +2

    This is only comparing the first and last character. This program would call "YESTERDAY" a palindrome even though it is not.
    Also, I do not understand why a space made any difference. Can you explain that? The first and last character were still equal.

  • @user-ki9nj8mr1k
    @user-ki9nj8mr1k Рік тому

    nice and different starategy in teaching and also upload calcualtionpart

  • @efzo
    @efzo 3 роки тому +1

    God bless you Alex, you are a legend!!! Thanks for all you do😀

  • @lux27.42
    @lux27.42 5 років тому +3

    good video as always.. thanks :)

  • @JonesJutsu
    @JonesJutsu 3 роки тому +1

    Hey you saved me some tears

  • @HoanNguyen-fc8vb
    @HoanNguyen-fc8vb 4 роки тому +1

    It is very nice.Thank you very much!

  • @Tuxedo-Twins
    @Tuxedo-Twins 3 роки тому +2

    When you have the reverse string can’t we just do equals to check the original and reverse to make the decision on if palindrome true or not

  • @kcconsigo7429
    @kcconsigo7429 4 роки тому +1

    Great tutorial

  • @sefacorleone8276
    @sefacorleone8276 3 роки тому +2

    i ask myself, why you dont just use equals on Strings at the end , beginning with boolean palindrom ? i mean: originalString.equals(reversedString) == palindrom

    • @Na-cc9dx
      @Na-cc9dx 3 роки тому +2

      it is working, but what about capitalization? how can ignore it?

    • @sefacorleone8276
      @sefacorleone8276 3 роки тому +2

      @@Na-cc9dx use .toLowerCase() method on String. Or toUpperCase();

    • @sefacorleone8276
      @sefacorleone8276 3 роки тому +2

      @@Na-cc9dx The equalsIgnoreCase() method compares two strings, ignoring lower case and upper case differences. This method returns true if the strings are equal, and false if not. Tip: Use the compareToIgnoreCase() method to compare two strings lexicographically, ignoring case differences. With this its easier and you do not need to loop again. Better for Time and Space complexity.

  • @gitcat8160
    @gitcat8160 2 роки тому +1

    What is the difference between .length and .length() in Java

  • @josephthecreator
    @josephthecreator 2 роки тому

    Awesome video Alex, thank you.

  • @youvegotmail9385
    @youvegotmail9385 Рік тому

    Fantastic!

  • @aalokkumar9732
    @aalokkumar9732 3 роки тому +1

    do this question using single for loop

  • @philipgabrielc.bornea9221
    @philipgabrielc.bornea9221 4 роки тому +1

    Your awesome bro😉

  • @mahamamjad1086
    @mahamamjad1086 3 роки тому +1

    I am not able to understand why there is a minus 1 there

  • @shreyak6100
    @shreyak6100 2 роки тому

    Lets go!!

  • @crazierhiphopbeatzbydegriz5733
    @crazierhiphopbeatzbydegriz5733 2 роки тому

    Great!!! please do also, Data Structures tutorials.

  • @user-nm9uk3vf4w
    @user-nm9uk3vf4w 3 роки тому +1

    You're awesome ❤️

  • @PinoySinigang
    @PinoySinigang 4 роки тому +2

    Can anyone help me if you were to put this in a Scanner input?

  • @thathsaranibandara3281
    @thathsaranibandara3281 4 роки тому +1

    thank you!

  • @christopherkeller2930
    @christopherkeller2930 4 роки тому +8

    His keyboard sounds so Juicy

  • @jeyhunaliyev1765
    @jeyhunaliyev1765 3 роки тому +1

    Waiting more java videos but unfortunately no any notifications anymore 🧐

  • @georgea7850
    @georgea7850 3 роки тому +1

    Pseudo code : If user inputs the word and you store in word[] string array.. after conditioning the strlen couldn’t you just read from the End instead of decrement in the loop function?

  • @sarthoknextt5150
    @sarthoknextt5150 2 роки тому

    This is java interview question that i have faced recently..

  • @hiltonvusi7483
    @hiltonvusi7483 3 роки тому

    Thank you Alex🙏

  • @scottliu6042
    @scottliu6042 4 роки тому +1

    Can also use original.trim() as well instead of replace, right?

  • @mouneibintk9595
    @mouneibintk9595 3 роки тому

    great explanation

  • @saikiranvaishnav7546
    @saikiranvaishnav7546 3 роки тому +1

    Or,instead of another for loop,just compare the original and reverse with if statements.!

  • @coesmetic
    @coesmetic 7 місяців тому

    Why does it print out not a palindrome when i type in 'nurses run' without the 's'?

  • @Reptilectrik27
    @Reptilectrik27 2 роки тому +1

    I just dont understand why he has to subsract 1 from "int i = original.length()". Why start at 2 instead of 3?

    • @-hir0yat0-25
      @-hir0yat0-25 2 роки тому +1

      Indexing starts at 0 (position 1 = 0, position 2 = 1, position 3 = 2, etc.). So in his example, since there are 3 characters, index 3 doesnt exist, but original.lenght() would return 3 (since there are 3 characters). If he wants to start at the end, index 2 (position 3), he would have to -1 from the length of the original string.

  • @archiax1007
    @archiax1007 Рік тому

    My question is why you get a single line saying it's a palindrome or not, but when I use the exact same code it's give me a new line saying it is or isn't when it tests each character? How did I get these loop results to give me the one final line and not multiple lines each time it runs the loop?

  • @keeprunning5457
    @keeprunning5457 Рік тому

    very good excellent!

  • @poopass5308
    @poopass5308 2 роки тому

    savior

  • @alexsepelenco9902
    @alexsepelenco9902 3 роки тому +1

    It's not fool proof because of "A Man, a Plan, a Canal - Panama" strings that are not alphabets

  • @ScylenoMido
    @ScylenoMido 10 місяців тому

    Saved me 🙏

  • @yasseralkindi7350
    @yasseralkindi7350 2 роки тому

    I did it this way, a few lines of code less, works just fine...
    public class Palindrome {
    public static boolean checkPalindrome(String str){
    String original = str;
    String reversed="";//to store reversed str into

    for (int i= str.length()-1; i>=0; i--) { //starting at the end (length),
    reversed +=original.charAt(i);//adding char at i (going backwards)
    if (reversed.equals(original)) {

    }
    }
    return true;

    }

    public static void main(String[] args) {
    String str = "nurses run";
    if(checkPalindrome(str))
    System.out.println("The string is a palindrome!");
    else
    System.out.println("The string is not a palindrome!");
    }}

  • @Ryan-le2im
    @Ryan-le2im Рік тому

    Thanks x 100

  • @Deepak_mannai
    @Deepak_mannai 3 роки тому

    Nice teach

  • @kvelez
    @kvelez 11 місяців тому

    Cool program.

  • @germescraft
    @germescraft 2 роки тому

    thx

  • @rupeshkamble3331
    @rupeshkamble3331 Рік тому

    What is space and time complexity of this?

  • @dirisendiri7425
    @dirisendiri7425 2 роки тому

    can this program be made in recursion form?

  • @marctan9087
    @marctan9087 4 роки тому

    Are you using notepad++?

  • @tamannaniger7204
    @tamannaniger7204 3 роки тому

    Thanks

  • @OptionsOwnsU
    @OptionsOwnsU 2 роки тому

    Why iterate again to compare them and not use equals?

  • @takoyaki-sama6337
    @takoyaki-sama6337 3 роки тому

    how about when we gotta return true if its a palin. and false if not as a boolean type?

  • @adrianpaul8169
    @adrianpaul8169 4 роки тому

    nice tut.

  • @sabikaali5527
    @sabikaali5527 2 роки тому

    if (reverse==original){palindrome = true;} wouldn't this be simpler to do, instead of writing another loop?

    • @timothybritcliffe
      @timothybritcliffe Рік тому

      if(original.equals(reverse)){
      System.out.println("Is a palindrome!");
      } else {
      System.out.println("Not a palindrome.");
      That's how you would properly do it. But yes I see what you are getting at

  • @samarthvs3338
    @samarthvs3338 2 роки тому +1

    my solution without seeing the video-
    import java.util.Scanner;
    class palindrome
    {
    static String reverse(String s)
    {
    char[] letters = new char[s.length()];
    int ind = 0;
    for(int i = s.length() - 1; i >= 0; i--)
    {
    letters[ind] = s.charAt(i);
    ind++;
    }
    String reversed = "";
    for(int i = 0; i < s.length(); i++)
    {
    reversed = reversed + letters[i];
    }
    return reversed;
    }
    static boolean isPalindrome(String str)
    {
    if(reverse(str).equals(str))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    public static void main(String[] args)
    {
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter a number:");
    String num = sc.nextLine();
    if(isPalindrome(num))
    {
    System.out.println(num + " is a palindrome");
    }
    else
    {
    System.out.println(num + " is not a palindrome");
    }
    }
    }

  • @paia6447
    @paia6447 2 роки тому +1

    System.out.println(palindrome ? "Palindrome" : "Not a Palindrome");

    • @paia6447
      @paia6447 2 роки тому

      It's better to use this than if else statement

  • @vasilizaitsev7246
    @vasilizaitsev7246 3 роки тому

    Great

  • @bbftv495
    @bbftv495 2 роки тому

    goog

  • @anuragtavargiri6411
    @anuragtavargiri6411 4 роки тому

    celing gang hold up

  • @poppop-ez9st
    @poppop-ez9st 3 роки тому

    hmm u didnt have to do the boolean stuff.
    Cud have just done a simple if statement to check if it is palindrome. (sry if im wrong :P)

  • @zane8805
    @zane8805 5 років тому

    bro when you did String reverse = ""; and then reverse += i cringed you shouldve used StringBuffer reverse = new StringBuffer(); and then reverse.append("");

    • @heksqer1022
      @heksqer1022 5 років тому

      Why is that better than what's shown in the video ?

    • @zane8805
      @zane8805 5 років тому

      @@heksqer1022 just is mate

    • @heksqer1022
      @heksqer1022 5 років тому

      @@zane8805 so it's not

  • @hellenmarigu7070
    @hellenmarigu7070 10 місяців тому

    Computer is ucked up game circuit

  • @TheNEOWOW
    @TheNEOWOW 2 роки тому

    int i = word.length() - 1; why -1 here ? index started on 0.. i know but why -1 ?

  • @jiren6637
    @jiren6637 4 роки тому

    //user input -aayman shameem

  • @shitalkevadia5596
    @shitalkevadia5596 2 роки тому

    please try to explain every single detail like instead of telling us ' what' are you creating please go slow and explain 'how " in detail

  • @timothybritcliffe
    @timothybritcliffe Рік тому

    correct me if im wrong but couldnt you also do
    if(original.equals(reverse)){
    System.out.println("Is a palindrome!");
    } else {
    System.out.println("Not a palindrome.");
    to check if the word/phrase is a palindrome?