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,不知道问题出在哪里

解决方案 »

  1.   

    for (int i = 0; 0 < 10; i++) {0<10 这个条件是恒等的,所以该循环永远也不会结束。那么后面当然是:Unreachable code
      

  2.   

     for (int i = 0;i < 10; i++) {
                name[i] = input.next();
            }
      

  3.   

    差不多就是你的写法了:Scanner sc = new Scanner(new File("文本文件全路径"));
    List lst = new ArrayList(); // 因为文件行数不确定,所以还是用列表对象比较好
    while (sc.hasNextLine()) {
       lst.add(sc.nextLine());
    }
    sc.close();System.out.println(lst); // 可以输出来看看
      

  4.   

    用io流啊,readline,如果一行一行的存就直接存了,要分割的话就分割。
      

  5.   

    我也考虑这样写,能否写个例子呀 !我目前刚学java。
      

  6.   


    BufferedReader br =new BufferedReader(new FileReader("d:\\test.txt"));
    for (int i = 0; i < name.length; i++) {
    name[i] =  br.readLine();
    }
    刚找了些例子 我这样写的  符合我的初衷  谢谢你们!!!