Answers for "sorting program in java"

3

bubble sort java

public class DemoBubbleSort
{
   void bubbleSort(int[] arrNum)
   {
      int num = arrNum.length;
      for(int a = 0; a < num - 1; a++)
      {
         for(int b = 0; b < num - a - 1; b++)
         {
            if(arrNum[b] > arrNum[b + 1])
            {
               int temp = arrNum[b];
               arrNum[b] = arrNum[b + 1];
               arrNum[b + 1] = temp;
            }
         }
      }
   }
   void printingArray(int[] arrNum)
   {
      int number = arrNum.length;
      for(int a = 0; a < number; ++a)
      {
         System.out.print(arrNum[a] + " ");
         System.out.println();
      }
   }
   public static void main(String[] args)
   {
      DemoBubbleSort bs = new DemoBubbleSort();
      int[] arrSort = {65, 35, 25, 15, 23, 14, 95};
      bs.bubbleSort(arrSort);
      System.out.println("After sorting array: ");
      bs.printingArray(arrSort);
   }
}
Posted by: Guest on October-23-2020
2

sorting java

public class SortingData {
    public static void main(String[] args)
    {
        int[] arr = { 13, 7, 6, 45, 21, 9, 101, 102 };
  		
        Arrays.sort(arr);//sort() function
  
        System.out.printf("Modified arr[] : %s",
                          Arrays.toString(arr));
    }
}
Posted by: Guest on September-02-2021
0

sorting algorithms in java

Bubble Sort
Posted by: Guest on July-06-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language