import java.util.Scanner;public class DVDSet {
String name[] = new String[10];
int state[] = new int[10];
Scanner input = new Scanner(System.in); public void initial() {
System.out.println("请添加信息");
for (int i = 0; 0 < 10; i++) {
name[i] = input.next();
}
for (int j = 0; j < 10; j++) {
state[j] = (int) (Math.random() * 2); // 产生的随机数赋予数组
}
}}将代码保存后总是第二个循环提示Unreachable code,不知道问题出在哪里
name[i] = input.next();
}
List lst = new ArrayList(); // 因为文件行数不确定,所以还是用列表对象比较好
while (sc.hasNextLine()) {
lst.add(sc.nextLine());
}
sc.close();System.out.println(lst); // 可以输出来看看
BufferedReader br =new BufferedReader(new FileReader("d:\\test.txt"));
for (int i = 0; i < name.length; i++) {
name[i] = br.readLine();
}
刚找了些例子 我这样写的 符合我的初衷 谢谢你们!!!