This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.Random; | |
public class Sortir { | |
Random rand = new Random(); | |
public Sortir() { | |
String a = ""; | |
int m = 100; | |
for(int i=0; i< 12; i++){ | |
int aa = rand.nextInt(m); | |
int bb ; | |
if( aa % 2 != 0){ | |
bb = m-1 - aa; | |
}else{ | |
bb = m-1 - aa -1; | |
aa = aa + 1; | |
} | |
for(int j=0; j < bb/2; j++) | |
a = a+ " "; | |
for(int j=0; j< aa; j++) | |
a = a + "*"; | |
for(int j=0; j < bb/2; j++) | |
a = a+ " "; | |
list.add(a); | |
a = ""; | |
} | |
Collections.sort(list, new Comparator<String>() { | |
public int compare(String p1, String p2){ | |
return p1.lastIndexOf("*") > p2.lastIndexOf("*")? 1 | |
: p1.lastIndexOf("*") < p2.lastIndexOf("*")?-1:0; | |
} | |
}); | |
for(int i=0; i< list.size();i++){ | |
System.out.println(list.get(i)); | |
} | |
} | |
ArrayList<String> list = new ArrayList<>(); | |
public static void main(String[] args){ | |
new Sortir(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
********* | |
******************* | |
***************************** | |
***************************************** | |
*********************************************** | |
********************************************************* | |
*********************************************************** | |
*********************************************************** | |
*************************************************************** | |
***************************************************************** | |
************************************************************************* | |
******************************************************************************************* |