【发布时间】:2019-02-23 19:22:36
【问题描述】:
我对编程还是很陌生,我正在尝试做这个小程序,我在其中编写了一个静态方法,该方法接受一个字符串数组并返回一个整数。从那里我必须找到最小/最短字符串的索引位置并返回该索引值。我完全迷失了,并为此苦苦挣扎。我能得到一些帮助吗?
到目前为止我的代码...
public class test
{
public static void main(String [] args)
{
String [] Month = {"July", "August", "September", "October"};
smallest(Month);
System.out.println("The shortest word is " + smallest(Month));
}
public static String smallest(String Month[])
{
String first = Month[0];
for (int i = 1 ; i < Month.length ; i++)
{
if (Month[i].length()<first.length())
{
first = Month[i];
}
}
return first;
}
}
【问题讨论】:
-
到目前为止你尝试了什么?
-
可以分享代码吗?