为什么我的词典编程程序不能打印所有三个字符串?

时间:2016-12-04 18:26:58

标签: java

如您所见,我在下面有三个名称:s1,s2和s3。它应该将alpha命令放在一个新行上,但“Ashley”不会打印。 enter code here

public class Lex {
static String s1 = "Ashley";
static String s2 = "Joe";
static String s3  = "John";
    public static void main(String[] args) {
        String topString = "";
        String midString = "";
        String botString = "";

         if (s1.compareTo(s2) > 0 && (s1.compareTo(s3) > 0)) {
            topString = s1; }
            else if (s1.compareTo(s2) < 0 && (s1.compareTo(s3) > 0)) {
            midString = s1; }
                else{ botString = s1; }

         if (s2.compareTo(s1) > 0 && (s2.compareTo(s3) > 0)) {
            topString = s2; }
            else if (s2.compareTo(s1) < 0 && (s2.compareTo(s3) > 0)) {
            midString = s2; }
                else { botString = s2; }

         if (s3.compareTo(s2) > 0 && (s3.compareTo(s1) > 0)) {
            topString = s3; }
            else if (s3.compareTo(s2) < 0 && (s3.compareTo(s1) > 0)) {
            midString = s3; }
            else { botString = s3;}

            System.out.println(topString);
            System.out.println(midString); 
            System.out.println(botString);
    }
}

0 个答案:

没有答案