/* This program sorts out name in orders from
their first alphabetical orders .*/
package nameorder;
public class NameOrder {
public static void sayName(String a, String s, String d){
System.out.println("Name By Alphabetical Order: \n1."+a+"\n"+"2."+s+"\n3."+d+"\n");
}
public static void stringOrder(String a ,String s ,String d){
int i= a.compareTo(s) ;
int j= a.compareTo(d) ;
int k= d.compareTo(s) ;
int l= d.compareTo(a) ;
String first="";
String second="";
String third="";
if(i<0&&j<0){
first=a;
if(k>0&&l>0){
third = d;
second = s;
}else{
second = d;
third = s;
}
}else if(i>0&&j>0){
third=a;
if(k<0&&l<0){
first = d;
second = s;
}else{
second = s;
first = d;
}
}else{
second=a;
if(k<0&&l<0){
first = d;
third = s;
}else{
first = s;
third = d;
}
}
sayName(first,second,third);
}
public static void main(String[] args) {
String a ="C";
String s ="a";
String d ="h";
stringOrder(a.toUpperCase(),s.toUpperCase(),d.toUpperCase());
}
}
Ich frage mich nur, ob ich das richtig mache oder es gibt eine bessere kürzere Version dafür?Wie kann ich diesen Java-Code verkürzen?
[CodeReview.SE] (https://codereview.stackexchange.com/) – tkausl
[_ "Warum ist" Kann mir jemand helfen? "Keine eigentliche Frage?" _] (Https://meta.stackoverflow.com/questions/284236/why-is-cann-someone-help-me-not -an-actual-question), auch dies ist eher eine Code-Review-Anfrage, die hier nicht zum Thema gehört. –
https://stackoverflow.com/questions/13056178/java-sorting-an-string-array-by-a-substring-of-characters das kann helfen – Kaushal