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-王振哲1407064244 #31

Open
Vikingweirdo opened this issue Dec 25, 2015 · 0 comments
Open

JAVA1-王振哲1407064244 #31

Vikingweirdo opened this issue Dec 25, 2015 · 0 comments

Comments

@Vikingweirdo
Copy link

线程**********************************************
class A implements Runnable 
{   private String name ;
    private int Apple;
    public A(String name){
        this.name = name;
    }
    public void run(){
        for (Apple = 6;Apple >= 0 ;Apple-- )
        {
            System.out.println(name + "卖苹果:"+Apple);
        }
    }
}
public class ceshi extends Thread       
{   
    private String name;
    private int ticket;
    public ceshi(String name){
        this.name = name;
    }
    public void run(){
        for (ticket = 5 ;ticket>= 0 ;ticket-- )
        {
            System.out.println(name+"卖票: "+ticket);

        }
    }

    public static void main(String[] args){
        ceshi c1 = new ceshi("A");      //资源不共享
        ceshi c2 = new ceshi("B");
        ceshi c3 = new ceshi("C");
        c1.start();             
        c2.start();
        c3.start();
        System.out.println("*************************");
        A C = new A("老王");  //资源达到共享
        new Thread(C).start();  
        new Thread(C).start();
        new Thread(C).start();
    }
}
*********************************************************、
删羊List<String> AllList = null;
        AllList = new ArrayList<String>();
        AllList.add("Hello1");
        AllList.add("Hello2");
        AllList.add("Hello3");
        AllList.add("Hello4");
        AllList.add("Hello5");
        System.out.println(AllList);
        //System.out.println(AllList.get(0));
        List<String>SubList = AllList.subList(2,4);//通过截取部分集合删除羊1
        for (int i = 0;i <SubList.size();i++){
            System.out.println(SubList.get(i)+" ");
        }
        for (int i = 0;i <AllList.size()-2;i++){        //删除羊2
            System.out.print(AllList.get(i+2)+" ");
        }
        System.out.println();
        for (int i = 0 ; i < 3; i++){               //删除羊3
        AllList.remove(i);
        }
        System.out.println(AllList);

***********************************************************************
写文件import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
public class IOdemo
{
    public static void main(String[] args)throws Exception{
        File f = new File("e:"+File.separator+"text.txt");
        OutputStream out = new FileOutputStream(f);
        String st = "Hello world";
        byte b[] = st.getBytes();
        for (int i = 0;i<b.length ;i++ )
        {
            out.write(b[i]);
        }
        out.close();
    }
}
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