This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
|
java:comparable [2020/02/25 09:32] gthanos [Το interface java.util.Comparator] |
java:comparable [2020/02/26 21:11] gthanos |
||
|---|---|---|---|
| Line 118: | Line 118: | ||
| <code java> | <code java> | ||
| Arrays.sort(rectangles, | Arrays.sort(rectangles, | ||
| + | </ | ||
| + | |||
| + | <code java SortRectangleArray.java> | ||
| + | import java.util.Random; | ||
| + | import java.util.Arrays; | ||
| + | |||
| + | class SortRectangleArray { | ||
| + | | ||
| + | public static void main(String []args) { | ||
| + | Random rand = new Random(12345); | ||
| + | Rectangle []rectangles = new Rectangle[5]; | ||
| + | for(int i=0;i<5; i++) | ||
| + | rectangles[i] = new Rectangle(rand.nextInt(10), | ||
| + | | ||
| + | print_rectangles(rectangles); | ||
| + | Arrays.sort(rectangles, | ||
| + | print_rectangles(rectangles); | ||
| + | } | ||
| + | | ||
| + | public static void print_rectangles(Rectangle []rectangles) { | ||
| + | System.out.println(" | ||
| + | for(int i=0; i< | ||
| + | System.out.println(i+" | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
| Line 126: | Line 151: | ||
| </ | </ | ||
| - | | Προηγούμενο : [[ :java:generic_interface_example | + | | Προηγούμενο : [[ :java:abstract_classes_vs_interfaces |