Reverse an Array | Java | Program to reverse the contents of an Array

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • #Java #CoreJava #Collections #javaForBeginners Check out my Anime Store - anime-stoze.bl...
    Subscribe to my channel so that you do not miss any topics.
    The phone I used to record - amzn.to/34V1uqX
    Phone stand used - amzn.to/3igP9QZ
    Lighting I used - amzn.to/3IpYyQO
    My laptop - amzn.to/3L1gt1Z
    My gaming Keyboard - amzn.to/3Jt66mY
    My gaming Mouse - amzn.to/36B4eKE
    Headphones - amzn.to/3u3RnbC
    Find the code for the above program here - musclecode.blo...
    My other videos-
    Finding Reverse of a Number - • Finding Reverse of a N...
    Check if the given number is Prime Number - • Check if given number ...
    Finding Minimum and Maximum value from an Array - • Finding Minimum and Ma...
    Area and Perimeter of Rectangle - • Area and Perimeter of ...
    Program to check if a string is Palindrome - • Palindrome | Program ...
    Find the sum of digits of a number - • Find sum of digits of ...
    Count the number of Digits of a Number - • Count the number of Di...
    Java program to print Fibonacci Series - • Java program to print ...
    Find Factorial of a number - • Find Factorial of a nu...
    Check if a given year is Leap Year - • Check if a given year...
    C++ program to Swap two numbers (Using extra variable) - • C++ program to Swap tw...
    C++ program to find if a number is ODD or EVEN - • C++ program to find if...
    C++ program to find Quotient and Remainder - • C++ program to find Qu...
    C++ program to find Sum, Difference, Product, and Divison of two numbers - • C++ program to find Su...

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

  • @ankithareddy4497
    @ankithareddy4497 10 หลายเดือนก่อน +7

    for(int i=a.length-1;i>=0;i--) {
    System.out.println(a[i]);
    } you can give like this also simple method to reverse array

    • @BTechComputerScience
      @BTechComputerScience  10 หลายเดือนก่อน +4

      Hey there, this is also a good solution, but here all u can do is print in reverse order. Many interviewers won't accept this... they ll ask for an array which has reversed elements of the original array, which can be used for any other operation if needed. For example if the question says - reverse the array and find the index of the largest/smallest number in it.
      Hence leaning to create a reversed array is also important. 😊

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

    Worked!! I wondered after watching the video that how will it work for odd number of elements in array, but later realized that it does and why it does. Thanks for the video.

    • @pravarkunnath3519
      @pravarkunnath3519 ปีที่แล้ว

      Why does it work with odd array?

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

      @@pravarkunnath3519 In odd array there will be left a middle element right!
      We don't have to touch it, it will stay at its position only even after reversing.
      Hence It works
      Hope it helps
      Enjoy coding

  • @priyansh.u
    @priyansh.u 7 วันที่ผ่านมา

    Thank you so much🙏

  • @EarthWildEchoes
    @EarthWildEchoes 2 ปีที่แล้ว +1

    Great explanation, Thank you!

  • @mohammadshahid5538
    @mohammadshahid5538 4 หลายเดือนก่อน

    Make video on finding diagonal and indenity matrix

  • @paul5007
    @paul5007 11 หลายเดือนก่อน +2

    its always the indian guy
    Thank you

  • @SuryaSurya-zl4ok
    @SuryaSurya-zl4ok 2 หลายเดือนก่อน

    Then wht will be the given input is in odd number

  • @rohitshinde7518
    @rohitshinde7518 ปีที่แล้ว

    Very helpful Thank you boss

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

    thanks bro..i could not understand swapping part

  • @justinbabu8473
    @justinbabu8473 หลายเดือนก่อน

    Superb🎉

  • @Sulakshit
    @Sulakshit 8 หลายเดือนก่อน

    Bro what if it's not arranged in ascending or descending order ?

  • @rubencherukuri91
    @rubencherukuri91 ปีที่แล้ว

    Please explain" reverse string"

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

    This code doesn't work if there are duplicates in array

  • @HNTAutumnleaf
    @HNTAutumnleaf 6 หลายเดือนก่อน

    Nice video! But can you do it in recursive?😁

  • @Jobupdates29
    @Jobupdates29 7 หลายเดือนก่อน

    thank you

  • @aasimkhan271
    @aasimkhan271 2 ปีที่แล้ว +3

    why using j=a.lenght-1 ??

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

      Because the index of the array starts form 0, to access last index of the array you have to set array.lenght - 1.

    • @kartikpaul3161
      @kartikpaul3161 2 ปีที่แล้ว +3

      Uspe tum 5 bhi likh sakte ho

    • @harishkumarreddy1999
      @harishkumarreddy1999 7 หลายเดือนก่อน

      @@kartikpaul3161what if you don’t know the length of an array?

    • @naveenkumar6768
      @naveenkumar6768 6 หลายเดือนก่อน +2

      a.length - it is used to find the length of one particular array, here the array name is a, so we put a.length and the reason for a.length-1 is simple we just need the index to its common to do -1 with the length of that particular array, hope it's useful

    • @thakursclub6432
      @thakursclub6432 17 วันที่ผ่านมา

      Because the length of the array is 6 but the last index is 5 . So we did length-1

  • @mohammadshahid5538
    @mohammadshahid5538 4 หลายเดือนก่อน

    Make a video on binary search

    • @BTechComputerScience
      @BTechComputerScience  4 หลายเดือนก่อน

      I have a binary search video on my channel 🙃

    • @mohammadshahid5538
      @mohammadshahid5538 4 หลายเดือนก่อน

      @@BTechComputerScience ok I will check ✅

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

    good work bro :)
    can you use better equipment for audio it is not audible and voice is not clear

  • @unnatigupta1112
    @unnatigupta1112 2 หลายเดือนก่อน

    👌👌👌👌👌👌

  • @sagardarade
    @sagardarade 5 หลายเดือนก่อน

    Perfect✅

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

    Why in last array.tostring ?

    • @mafia53042
      @mafia53042 10 หลายเดือนก่อน

      it is a predefined method that shows arrays in a string format
      and similarly for 2d arrays we use arrays.deepToString method for output

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

    Error vasthundhi bro
    Last lo sop lo (array.to string (a));. ???

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

      Arrays.toString(a)

    • @Notfound.5019
      @Notfound.5019 2 ปีที่แล้ว

      you need to import import java.util.Arrays;

    • @sanskar2404
      @sanskar2404 6 หลายเดือนก่อน

      ​@@BTechComputerSciencewhy we use of it....we can write any other thing instead of it?

  • @23mechnikilkannak59
    @23mechnikilkannak59 2 ปีที่แล้ว

    Nice but we can't see your code

  • @pablopronsky7364
    @pablopronsky7364 ปีที่แล้ว

    you are the beast

  • @gollarama2559
    @gollarama2559 ปีที่แล้ว

    Tell me reverse string bro

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

    Error code .

  • @yogeshchoudhary6839
    @yogeshchoudhary6839 7 หลายเดือนก่อน

    100/100

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

    Bro getting errors

  • @gayathridhana1000
    @gayathridhana1000 ปีที่แล้ว

    Thank you