暑假自学(34)

今天的任务主要是作做业,虽然视频还差几十章没有看,今天完成了之前没有完成的c++做业,其中有一个代码使我疑惑,以下:c++

public class 素数编程

{数组

   public static void main(String args[]) throws IOException网络

     {多线程

      File file=new File("E:\\f2.txt");线程

      BufferedReader a=new BufferedReader(new FileReader(file));视频

      dog dog1=new dog(14,15);get

      String data;网络编程

      int i=0;io

      ArrayList b=new ArrayList();

      while((data=a.readLine())!=null)

      {

       b.add(data);

      }    

     String c=(String)b.get(0);

     String j=(String)b.get(1);

     int m= Integer.parseInt((String)c.subSequence(9,11));

     int l= Integer.parseInt((String)j.subSequence(9,11));

     dog dog2=new dog(l,m);

     System.out.println("dog2的体重为:"+dog2.getweight());

     System.out.print("dog2的年龄为:"+dog2.getage());

      a.close();

     }   

}

class dog

{

    private

    int age;

    int weight;

    dog(int a,int b)

    {

        age=a;

        weight=b;

    }

    dog(){};

    public int getage()

    {

        return age;

    }

    public int getweight()

    {

        return weight;

    }

}

这道代码最让我疑惑的是为何用数组来保存文件的数据,反而用集合能够,除此以外我还比较疑惑的是readline的用法,直到网上查了一下才发现readline的真正用法。总的来讲,作了这几道题对个人帮助很大,明天我会继续完成剩下的几道文件题,而后在自学剩下的多线程和网络编程。