Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java1-王蕊芳1407094106 #15

Open
RuiFangW opened this issue Dec 22, 2015 · 0 comments
Open

Java1-王蕊芳1407094106 #15

RuiFangW opened this issue Dec 22, 2015 · 0 comments

Comments

@RuiFangW
Copy link

1. 作业一

        Iterator<Sheep> iter=sheepList.iterator();
        int num=0;
        while(iter.hasNext()&&num<3){
            Sheep l=(Sheep)iter.next();
//      1.  if((l.name).equals("懒羊羊")){
//              iter.remove();
//          }
//      2.  if(sheepList.size()>2){
//              iter.remove();
//          }
//      3.  iter.remove();
//          num++;
        }
        for(int i=0;i<sheepList.size();i++)
        {
            //Sheep l=iter.next();
            System.out.println(((Sheep)(sheepList.get(i))).name);   
        }

2. 作业二

        String[] filenames=manyfile.list();
        for(int i=0;i<filenames.length;i++){
            String path=filenames[i];
            file=new File(manyfile,filenames[i]);
            FileOutputStream oos=null;
            String s="我真"+i;
            try {
                oos=new FileOutputStream(file);
                try {
                    oos.write(s.getBytes());
                    //oos.write(i);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

3. 作业三

public static void main(String[] args) {
        ThreadExtend h1=new ThreadExtend("一号");
        ThreadExtend h2=new ThreadExtend("二号");
        ThreadExtend h3=new ThreadExtend("三号");

        h1.start();
        h2.start();
        h3.start();//Thread

        Thread r1=new Thread(new ThredImp1());
        Thread r2=new Thread(new ThredImp1());
        Thread r3=new Thread(new ThredImp1());
        r1.start();//线程不能重复启动
        r2.start();
        r3.start();//runnable
    }

}
class ThredImp1 implements Runnable{
    public String name;

    public void run(){

        System.out.println(Thread.currentThread().getName());
    }
}
class ThreadExtend extends Thread{
    public ThreadExtend(String name){
        super(name);
    }
    public ThreadExtend(){
        super();
    }
    public void run(){
        for(int i=0;i<5;i++){
            System.out.println("我是"+this.getName()+i);
        }
    }
        //runnable和thread的区别:
        //.1.;避免单继承的局限性2.便于资源共享
@onlylemi onlylemi changed the title 王蕊芳1407094106 Java1-王蕊芳1407094106 Dec 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant