该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package 整数集合;
import java.util.*;
public class 整数集合 {
public static void main(String[] args) {
Vector 数集 = new Vector();
int choice;
int shu, num;
Scanner input = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
数集.addElement(input.nextInt());
}
for (int i = 0; i < 10; i++) {
System.out.print(数集.get(i) + " ");
}
String c;
do {
System.out.println("数集程序功能:");
System.out.println("1.增加");
System.out.println("2.删除");
System.out.println("3.修改");
System.out.println("4.查找");
System.out.println("5.Exit");
System.out.println("输入你的选择:");
choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("你要增加的数:");
shu = input.nextInt();
数集.addElement(shu);
break;
case 2:
System.out.println("删除数字位置:");
shu = input.nextInt();
数集.removeElementAt(shu);
break;
case 3:
try {
System.out.println("修改数字位置:");
num = input.nextInt();
System.out.println("新数:");
shu = input.nextInt();
数集.setElementAt(num, shu);
} catch (Exception e) {
System.out.println("不能超过" + 数集.size());
} finally {
}
break;
case 4:
num = input.nextInt();
System.out.printf("%s", 数集.contains(num));
break;
case 5:
break;
}
for (int i = 0; i < 数集.size(); i++) {
System.out.print(数集.get(i) + " ");
}
System.out.println("继续?yes/no");
c = input.nextLine(); // 用eclipse运行,为什么这个不能写入,换成数字的又行呢
} while (c.equals("yes"));
}
}