How to sort integer array in Java ? - Ascending/Descending order ? Java tutorial for beginners !

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

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

  • @dreamdot9686
    @dreamdot9686  4 ปีที่แล้ว +6

    Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java or Python programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .

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

      Hi, are you still doing this?

  • @Barak_Mozes
    @Barak_Mozes ปีที่แล้ว +6

    The code you provided is almost correct !
    public static void sortArray(int[] array) {
    int temp;
    for (int i = 0; i < array.length - 1; i++) {
    for (int j = i + 1; j < array.length; j++) {
    if (array[i] > array[j]) {
    temp = array[i];
    array[i] = array[j];
    array[j] = temp;
    }
    }
    }
    }

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

      so to call that method do i just write this
      sortArray(v)
      v is an array and do I need to put it in a for loop or just like that?

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

    Guys if you want to do it without so much trouble you can either use Arrays.sort()-->it arrange the array in ascending order
    Ex:
    int[] arr ={22,11,33,1};
    Arrays.sort(arr);
    System.out.println(Arrays.toString(arr);
    Output-->[1,11,22,33]
    Or else you can just write the code given in the video it will help you as u might have to arrange the array in the descending order.

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

    Looked so long for how to sort in descending order, you saved me, thanks sir!!

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

      My pleasure dude .. Happy learning ! If you wish to have one to one java classes any time in your career .. Don't forget to contact us at dreamdot1709@gmail.com

  • @PS-on1nh
    @PS-on1nh 2 ปีที่แล้ว +1

    Bro ur video very useful,pls upload video for
    Ques is:merge two arrays and sort the array in ascending and remove the duplicate elements from the array in one program
    A[ ]={2,3,1,4,5,6,7};B[ ]={7,10,8,6,8,6,9}

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

    can you explain the backend logic for this program?

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

    5:30 must

  • @C.Sakthivignesh
    @C.Sakthivignesh ปีที่แล้ว +2

    Thanks sir for made this video.

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

    thank you. what is the name of this algorithm

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

    great explanation,but why didn't you start j at i+1? considering you are not comparing the first element with itself.

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

      Valid point mate .. we can very well do it ..

    • @Raven-ql3im
      @Raven-ql3im 3 ปีที่แล้ว

      That's also my question, I've also seen it but what is the difference between j=i+1 and j=1 ?

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

      @@dreamdot9686 sir I did too..the end test cases are showing time limit exceed when some large arrays are given as input

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

      @@Raven-ql3im j = j+1 starts comparing i with the next element directly and what j=1 does is that it makes it first compare i to itself then move on to the next element. Both cases work since our condition is > and not >=

    • @ABHAYSINGH-op2rm
      @ABHAYSINGH-op2rm 2 ปีที่แล้ว

      Because by doing j=i+1 you will not traverse all the elements all the time. So we have to put j=i

  • @guna_777
    @guna_777 3 หลายเดือนก่อน +1

    tnx way too much helpfull :)

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

      Appreciate your comments

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

    Hi... Can you please explain what you used in for loop to print the sorted array..

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

      Concept is to compare each element of the array with all other elements and swap them if it is greater or smaller based on the order .. if we continue doing it .. at the end you ll get sorted array .. check the video as I have step by step explanation .. please write to us for any further questions

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

      Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .

  • @thuppadalokanath5444
    @thuppadalokanath5444 10 หลายเดือนก่อน +1

    thank you sir 😍

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

    Good mornig sir

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

    Thank You sir

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

    Thanks for this!

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

    this was great! Thank You

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

    Thank you

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

    this video is so help ful thank you pro

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

      Our pleasure bro .. Anytime if you wish to have one to one java classes don't hesitate to contact dreamdot1709@gmail.com

  • @osa-_-
    @osa-_- 3 ปีที่แล้ว +2

    5:42

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

    This video was so helpful. Thank you!

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

      Our pleasure.. Anytime if you wish to have one to one java classes don't hesitate to contact dreamdot1709@gmail.com

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

    very helpful

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

    Great video! but may I ask if what was the point of this code
    temp=num[i];
    num[i]=num[j];
    num[j]=temp;

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

      This code will swap the values in i'th and j'th position using a temporary variable

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

    What id love to know is why do people refer to using the merge sort algorithm when something like this is so much simpler and less coding overall. What’s so special about merge sort???

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

      It could be the execution time .. normally when choosing an algorithm for sorting we should rely on efficiency . May be you can compare the time difference between these 2 algos ..

  • @hey-uo2ru
    @hey-uo2ru 3 ปีที่แล้ว +1

    Exactly my idea at first to do this but failed then looked it up

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

    Nice job, the best and the simplest code.

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

      Thanks mate

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

      Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .

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

    bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?

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

      Hi .. we shouldn't use inbuilt functions for solving such problems .. companies will try to test your logical thinking in programs .. so always write your logic and avoid using inbuilt functions

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

    I was tasked to fill an array with random numbers and then check if its in increasing order or not how do i simply check for an order? Thanks

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

      To check if the elements are in increasing order .. you can iterate through the array and compare every i th element with i+1 th element..

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

    Is this binary sort?

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

      This is selection sort

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

    Can we give this example in bubble sort??

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

      Yess .. it's selection sort .. if possible ll share video on bubble sort soon

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

    Sir app jis pr coding kr rha ho bo bali link chiya mujhe

  • @MuhammadTalha-ui1qd
    @MuhammadTalha-ui1qd 3 ปีที่แล้ว +2

    take and array from the user and sort it in assending order and then calculate its median and mode
    any one solve this rapidly

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

      Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .

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

    KVM

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

    shouldn't be i+1? otherwise, you are saying 44 > 44?

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

      Yep you can very well do that ... It's a miss from my end

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

    Sir ap program konse software m krte h

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

      You can use any code editor which supports java .. I have used eclipse IDE

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

    👍

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

    font name?

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

    KDE

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

    Which sorting is this

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

      Bubble sort

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

      Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .

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

    font name?