Java实现 蓝桥杯VIP 算法训练 最长字符串

题目描述
字符串可是比赛经常出的问题,那么给大家出一个题,

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

输入

输出

样例输入
one two three four five
样例输出
three

import java.util.Scanner;


public class 最长字符串 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a[] = new String[5];
		int max = 0;// 最长字符串的位数
		int t = 0;// 记录第几个字符串位数最大
		for (int i = 0; i < 5; i++) {
			a[i] = sc.next();
			if (max < a[i].length()) {
				max = a[i].length();
				t = i;
			}
		}
		System.out.println(a[t]);
	}


}

原文地址:https://www.cnblogs.com/a1439775520/p/12948574.html