【发布时间】:2017-08-18 15:48:31
【问题描述】:
/* 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());
}
}
我只是想知道我这样做是对的还是有更好的更短版本?
【问题讨论】:
-
"Why is “Can someone help me?” not an actual question?",这也是一个代码审查请求,这里是题外话。
-
直到那里我才知道,但它让我清楚地了解了我在学习中的进一步期望,谢谢
标签: java