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-孔德林1507084235 #24

Open
onli-alin opened this issue Dec 24, 2015 · 0 comments
Open

Java1-孔德林1507084235 #24

onli-alin opened this issue Dec 24, 2015 · 0 comments

Comments

@onli-alin
Copy link

删羊

int a = sheepList.size() - 1;
for(int i=sheepList.size() - 1 ; i >= a - 3 ; i --){
        sheepList.remove(i);
}
System.out.println(sheepList);

创建文件

    File fe = new File("b://leihous");
    try{
    if(!fe.exists()){
        fe.mkdir();
    }
    FileOutputStream nu = null;
    File file = null;
    for(int i = 1;i <= 10;i++){
        file = new File(fe,"HelloWorld"+i+".txt");
        nu = new FileOutputStream(file);
        if(!file.exists()){
            file.createNewFile();
        }
        String str ="我真 "+i;
        byte[]  b = str.getBytes();
        nu.write(b);
        nu.flush();
        nu.close();
    }
}catch(IOException  e){
    e.printStackTrace();
}
}
}

thread和runnable的区别

//thread是单继承,runnable可以多个线程同时处理同一个变量

private int ticket = 10;  
private String name;  
public MyThread(String name){  
    this.name =name;  
}  

public void run(){  
    for(int i =0;i<500;i++){  
        if(this.ticket>0){  
            System.out.println(this.name+"卖票---->"+(this.ticket--));  
        }  
    }  
}  
}  


public static void main(String[] args) {  
    MyThread mt1= new MyThread("一号窗口");  
    MyThread mt2= new MyThread("二号窗口");  
    MyThread mt3= new MyThread("三号窗口");  
    mt1.start();  
    mt2.start();  
    mt3.start();  
}  

}

private int ticket = 10;  
private String name;  
public MyThread(String name){  
    this.name =name;  
}  

public void run(){  
    for(int i =0;i<500;i++){  
        if(this.ticket>0){  
            System.out.println(this.name+"卖票---->"+(this.ticket--));  
        }  
    }  
}  

}

public static void main(String[] args) {  
    MyThread mt1= new MyThread("一号窗口");  
    MyThread mt2= new MyThread("二号窗口");  
    MyThread mt3= new MyThread("三号窗口");  
    mt1.start();  
    mt2.start();  
    mt3.start();  
}  
}  



private int ticket =10;  
private String name;  
public void run(){  
    for(int i =0;i<500;i++){  
        if(this.ticket>0){  
            System.out.println(Thread.currentThread().getName()+"卖票---->"+(this.ticket--));  
        }  
    }  
}  
 }  


public static void main(String[] args) {  
    // TODO Auto-generated method stub  
    //设计三个线程  
     MyThread1 mt = new MyThread1();  
     Thread t1 = new Thread(mt,"一号窗口");  
     Thread t2 = new Thread(mt,"二号窗口");  
     Thread t3 = new Thread(mt,"三号窗口");  
    //MyThread1 mt2 = new MyThread1();  
    //MyThread1 mt3 = new MyThread1();  
     t1.start();  
     t2.start();  
     t3.start();  
}  
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