按字母顺序排列数组后,我需要添加一个 for 循环操作来搜索其中一个数组中的特定元素。
在这种情况下,我需要搜索“Rogers. Steve”。我应该如何进行?
预先感谢您的所有帮助!
我已经尝试了几个例子,但我无法得到正确的结果......
String[] arrayString=new String[]{
"Administrator",
"Vale.Vicky",
"Lane.Lois",
"Kent.Clark",
"Wayne.Bruce",
"Parker.Peter",
"Rogers.Steve",
"Luther.Lex",
"Osborn.Harry",
"Tony.Stark"};
String searchString="Rogers.Steve";
//Loop until the length of the array
//Print the index of the string on an array
System.out.println("Rogers.Steve");
我的课。
package helloworldjavabook;
public class HelloWorldjavabook {
public static void main(String[] args) {
String[] user = {"Administrator", "Vale.Vicky", "Lane.Lois", "Kent.Clark", "Wayne.Bruce",
"Parker.Peter", "Rogers.Steve", "Luther.Lex", " Osborn.Harry", "Tony.Stark"};
orderedGuests(user);
String[] password = {"PASSWORD1", "ILOVEBRUCE", "ILOVECLARK", " ILOVELOIS", "IAMGOTHAM", "IAMSPECTACULAR",
"IAMAMERICA", "IRUNLEXCORP", "IAMGREENGOBLIN", " IAMINVINCIBLE"};
orderedGuests(password);
String id[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
orderedGuests(id);
}
private static void orderedGuests(String[] hotel) {
Arrays.sort(hotel);
System.out.println(Arrays.toString(hotel));
}
}
一只甜甜圈
UYOU
相关分类