Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
public class DutchNationalFlag {
|
||||
enum DutchColors {
|
||||
RED, WHITE, BLUE
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
DutchColors[] balls = new DutchColors[12];
|
||||
DutchColors[] values = DutchColors.values();
|
||||
Random rand = new Random();
|
||||
|
||||
for (int i = 0; i < balls.length; i++)
|
||||
balls[i]=values[rand.nextInt(values.length)];
|
||||
System.out.println("Before: " + Arrays.toString(balls));
|
||||
|
||||
Arrays.sort(balls);
|
||||
System.out.println("After: " + Arrays.toString(balls));
|
||||
|
||||
boolean sorted = true;
|
||||
for (int i = 1; i < balls.length; i++ ){
|
||||
if (balls[i-1].compareTo(balls[i]) > 0){
|
||||
sorted=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("Correctly sorted: " + sorted);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue