//上机练习1
import java.util.Scanner;
public class Qing4 {
String[] names = new String[10];
public void addName(String name) {
for (int i = 0; i < names.length; i++) {
if (names[i] == null) {
names[i] = name;
break;
}
}
}
public void showNames() {
System.out.println("******************");
System.out.println("客户姓名列表:");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]);
}
}
public static void main(String[] args) {
Qing4 st = new Qing4();
Scanner input = new Scanner(System.in);
boolean a = true;
while (a) {
System.out.println("请输入客户姓名:");
String newName = input.next();
st.addName(newName);
System.out.println("继续输入吗?(y/n)");
String jixu = input.next();
if (jixu.equals("y")) {
a = false;
}
}
st.showNames();
}
}
第十四章 上机练习1
最新推荐文章于 2021-03-03 14:49:24 发布