java找出最长字符串
2021-04-01 06:28
标签:hang imp public out main next exti util 编写程序 题目:编写程序,针对输入的N个字符串,输出其中最长的字符串 输入样例: 4 输出样例: 最长的字符串:zhangming java找出最长字符串 标签:hang imp public out main next exti util 编写程序 原文地址:https://www.cnblogs.com/Iolo/p/13544356.html
zhaoming
zhangming
sunming
limingimport java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int count = 0;
String[] arr = new String[t];
for (int i = 0; i ) {
arr[i] = sc.next();
}
for (int i = 0; i ) {
if (arr[i].length() > arr[count].length()){
count = i;
}
}
System.out.println("最长的字符串:"+arr[count]);
}
}