码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-04-22 00:12:30      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:bsp   输出   void   string   auth   字符   static   mail   nbsp   

 

/**
* 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”} 中的长度最大的元素,并打印输出。

标签:bsp   输出   void   string   auth   字符   static   mail   nbsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!