JAVA常见算法题(二十九)

时间:2021-04-23 04:37:31
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);
}
}

 

运行结果:

JAVA常见算法题(二十九)