标签:hang imp public out main next exti util 编写程序
题目:编写程序,针对输入的N个字符串,输出其中最长的字符串
输入样例:
4
zhaoming
zhangming
sunming
liming
输出样例:
最长的字符串:zhangming
import 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 < t; i++) { arr[i] = sc.next(); } for (int i = 0; i < arr.length; i++) { if (arr[i].length() > arr[count].length()){ count = i; } } System.out.println("最长的字符串:"+arr[count]); } }
标签:hang imp public out main next exti util 编写程序
原文地址:https://www.cnblogs.com/Iolo/p/13544356.html