【发布时间】:2015-10-17 00:04:32
【问题描述】:
我真的在这部分问题上苦苦挣扎。我已经看了好几个小时的视频并在网上进行了研究,但我似乎无法正确理解。我需要生成一个 for 循环来检查 meg 的字符串,删除它并移动剩余的元素。这不是一个数组列表。
编写第二个传统的 for 循环来检查每个 字符串的元素“ 梅格 ”,如果在 数组,删除它,移动剩余元素,并显示名称数组。
我知道我的 for 循环会在我的最后一个客户名称和用于打印它的 for 之间进行。我只是不知道下一步该做什么。
这是我当前的代码:
public class CustomerListerArray {
public static void main(String[] args) {
String customerName[] = new String[7];
customerName[0] = "Chris";
customerName[1] = "Lois";
customerName[2] = "Meg";
customerName[3] = "Peter";
customerName[4] = "Stewie";
for (int i = customerName.length - 1; i > 3; i--) {
customerName[i] = customerName[i - 2];
}
customerName[3] = "Meg";
customerName[4] = "Brian";
for (String name: customerName) {
System.out.println(name);
}
}
}
【问题讨论】:
标签: java arrays string for-loop