package com.forezp.util; import java.util.Scanner; /** * 判断输入的5个字符串的最大长度,并输出 * * * @author Administrator * */ public class StringDemo{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String[] str =new String[5]; for(int x = 0; x<str.length;x++){ str[x] = sc.nextLine(); } String s = str[0]; for(int x = 1;x<str.length;x++){ if(str[x].length()>s.length()){ String temp = str[x]; str[x] =s; s = temp; } } System.out.println(s); } }
运行结果: