Sort double Array Example /*    Java Sort double Array Example    This example shows how to sort a double ...

Sort double Array Example

08:04 PASSOVE INCOME 2 Comments


             Sort double Array Example

  1. /*
  2.    Java Sort double Array Example
  3.    This example shows how to sort a double array using sort method of Arrays class of
  4.    java.util package.
  5. */
  6. import java.util.Arrays;
  7. public class SortDoubleArrayExample {
  8.   public static void main(String[] args) {
  9.    
  10.     //create double array
  11.     double[] d1 = new double[]{3,2,5,4,1};
  12.    
  13.     //print original double array
  14.     System.out.print("Original Array :\t ");
  15.     for(int index=0; index < d1.length ; index++)
  16.       System.out.print("  "  + d1[index]);
  17.    
  18.     /*
  19.      To sort java double array use Arrays.sort() method of java.util package.
  20.      Sort method sorts double array in ascending order and based on quicksort
  21.      algorithm.
  22.      There are two static sort methods available in java.util.Arrays class
  23.      to sort a double array.
  24.     */
  25.    
  26.     //To sort full array use sort(double[] d) method.
  27.     Arrays.sort(d1);
  28.    
  29.     //print sorted double array
  30.     System.out.print("\nSorted double array :\t ");
  31.     for(int index=0; index < d1.length ; index++)
  32.       System.out.print("  "  + d1[index]);
  33.      
  34.     /*
  35.       To sort partial double array use
  36.       sort(double[] d, int startIndex, int endIndex) method where startIndex is
  37.       inclusive and endIndex is exclusive
  38.     */
  39.    
  40.     double[] d2 = new double[]{5,2,3,1,4};
  41.     Arrays.sort(d2,1,4);
  42.    
  43.     //print sorted double array
  44.     System.out.print("\nPartially Sorted double array :\t ");
  45.     for(int index=0; index < d2.length ; index++)
  46.       System.out.print("  "  + d2[index]);
  47.   }
  48. }
  49. /*
  50. Output Would be
  51. Original Array :     3.0  2.0  5.0  4.0  1.0
  52. Sorted double array :     1.0  2.0  3.0  4.0  5.0
  53. Partially Sorted double array :     5.0  1.0  2.0  3.0  4.0
  54. */

2 comments:

  1. What is a free spins bonus? - Casino Roll
    An 가입머니주는사이트 example of a free spins is in a video 토토 검증 먹튀 랭크 slot, 메이저벳 with which you'll receive a cash bonus. 부들 이 벗방 When you play online slots, the bonus is a cash bonus and the free spins 스포츠분석

    ReplyDelete
  2. The Best Live Dealer Casino Apps In India
    The best Live 용인 출장안마 Dealer Casino app for India. Learn how to 영천 출장마사지 integrate live casino 안성 출장안마 games with top 과천 출장안마 providers like DraftKings, Evolution and 안양 출장안마 Bet365. Rating: 3 · ‎1 vote

    ReplyDelete