首页 > 编程语言 > 详细

本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并打印输出。

时间:2017-04-22 00:14:08      阅读:335      评论:0      收藏:0      [点我收藏+]

 

/**
* Homework14
*
* @Description:本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”,
* “congratulation”, “great”} 中的长度最大的元素,并打印输出。
* StringDemo01
*
* @author 
*
* email: 1816274408@qq.com 2017年4月18日下午6:33:59
*
*/
public class StringDemo01 {
public static void main(String[] args) {
String[] arr = { "welcome", "china", "hi", "congratulation", "great" };
System.out.print("原字符串数组为:\t");
for (String x : arr) {
System.out.print(x + " ");
}

String str = arr[0];
for (int i = 0; i < arr.length - 1; i++) {
if (arr[i].length() < arr[i + 1].length()) {
str = arr[i + 1];
}
}

System.out.println("\n 该数组长度最大的元素为:" + str);

}

}

本程序找出字符串数组 String[] arr = {“welcome”, “china”, “hi”, “congratulation”, “great”} 中的长度最大的元素,并打印输出。

原文:http://www.cnblogs.com/Jack1816274408/p/6746428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!