Java 最长字符串

求出5个字符串中最长的字符串。每个字符串长度在100以内,且全为小写字母。

样例输入

one two three four five

样例输出

three

代码:

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();
        String s4 = sc.next();
        String s5 = sc.next();
        String l ;
        if(s1.length()>s2.length()){
            l = s1;
        }else {
            l = s2;
        }
        if(l.length()<s3.length()){
            l = s3;
        }
        if(l.length()<s4.length()){
            l = s3;
        }if(l.length()<s5.length()){
            l = s3;
        }
        System.out.println(l);
    }
}

猜你喜欢

转载自blog.csdn.net/a215012954/article/details/86531437