Advertisement
zsoltizbekk

ora3_1

Sep 28th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. package zsolt_3ora;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Comparator;
  5.  
  6. public class Zsolt_3ora {
  7.  
  8.     public static void main(String[] args) {
  9.         /*
  10.         int t[];
  11.         t = new int[10];
  12.         t[0] = 7;
  13.         t[1] = 4;
  14.         t[2] = 2;
  15.         t[3] = 0;
  16.         t[4] = 9;
  17.         t[5] = 1;
  18.         t[6] = 5;
  19.         t[7] = 8;
  20.         t[8] = 6;
  21.         t[9] = 3;
  22.         */
  23.         /*
  24.         int[] t;
  25.         int a, b, c;
  26.         t = new int[] {7, 4, 2, 0, 9, 1, 5, 8, 6, 3};
  27.         */
  28.        
  29.         int[] t={7, 4, 2, 0, 9, 1, 5, 8, 6, 3};
  30.         int a, b, c;
  31.        
  32.         System.out.println(t);
  33.         System.out.println(Arrays.toString(t));
  34.         for (int i = 0; i < t.length; i++) {
  35.             if (i > 0) {
  36.                 System.out.print(" ");
  37.             }
  38.             System.out.print(t[i]);
  39.         }
  40.         System.out.println(System.getProperty("line.separator"));
  41.         System.out.println("The End");
  42.         for (int u : t) { //bejΓ‘rja a tΓΆmb elemeit egyszer
  43.             System.out.println(u);
  44.  
  45.         }
  46.        
  47.         Integer[] ti= new Integer[t.length];
  48.        
  49.         for (int i = 0; i < ti.length; i++) {
  50.             ti[i] = t[i];
  51.         }
  52.         Arrays.sort(t);
  53.         System.out.println(Arrays.toString(t));
  54.         System.out.println(Arrays.toString(ti));
  55.        
  56.         Comparator<Integer> s = new sajat_comparator();
  57.         Arrays.sort(ti,s);
  58.         System.out.println(Arrays.toString(ti));
  59.        
  60.     }
  61.  
  62. }
  63.  
  64.  
  65. //sajat_comparator
  66.  
  67. package zsolt_3ora;
  68.  
  69.  
  70. import java.util.Comparator;
  71.  
  72. /*
  73.  * To change this license header, choose License Headers in Project Properties.
  74.  * To change this template file, choose Tools | Templates
  75.  * and open the template in the editor.
  76.  */
  77.  
  78. /**
  79.  *
  80.  * @author hallgato
  81.  */
  82. public class sajat_comparator implements Comparator<Integer> {
  83.  
  84.     @Override
  85.     public int compare(Integer o1, Integer o2) {
  86.         //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  87.        
  88.         if (o1 < o2){
  89.             return -1;
  90.         }
  91.         if (o1 > o2){
  92.             return 1;
  93.         }
  94.         return 0;
  95.     }
  96.    
  97.    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement