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

java-杨浩东 1507084225 #32

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

java-杨浩东 1507084225 #32

DreamYHD opened this issue Dec 25, 2015 · 0 comments

Comments

@DreamYHD
Copy link
Member

1 删除羊

        Iterator<String> sheepss = sheeps.iterator();
        int i = 0;
                方法
         while (sheepss.hasNext()) {

         System.out.println(sheepss.next());
         i++;
         if (i > 2) break;
              }

        for(Iterator sheepss1 = sheeps.iterator();sheepss1.hasNext();){
            System.out.println(sheepss1.next());

        }
               方法二
        for (Object str : sheeps) {
        if (i < 3) {
            System.out.println(str.toString());
        }
        i++; 
           //i>3的时候删去前面的
        }

            方法三
          for(int i=0;i<sheeps.size();i++){ System.out.println(sheeps.get(i));

          } System.out.println("删除后三个");

         for(int i=0;i<sheeps.size()-3;i++){
          System.out.println(sheeps.get(i));

          } System.out.println("删除前两个"); 
             for(int  i=sheeps.size()-1;i>sheeps.size()-4;i--){
          System.out.println(sheeps.get(i));

          }


    }

2 Thread Runnable

     //Runnable 代码被多个线程共享;
    public void run() {
        while (num > 0) {
            num--;
            System.out.println(Thread.currentThread().getName() + "减少了一" + "  "
                    + num);
        }

    }
           MyThread a = new MyThread();
           Thread b = new Thread(a, "one");
           Thread c = new Thread(a, "two");
           Thread d = new Thread(a, "three");
             b.start();
             c.start();
             d.start();
    //Thread    JAVA单继承方式
       public void run() {
        while (num > 0) {
            num--;
            System.out.println(name + "减少了一" + "  " + num);

        }
    }
        Mythread a = new Mythread("first");
        Mythread b = new Mythread("second");
        Mythread c = new Mythread("third");
             a.start();
             b.start();
             c.start();

3写入文件我真 i

            for (int i = 0; i < 10; i++) {

                file = new File(manyfile, "helloworld" + i + ".txt");
                if (!file.exists()) {
                    file.createNewFile();

                }
            }
        for (int i = 0; i <= 9; i++) {
            file = new File(manyfile, "helloworld" + i + ".txt");
            OutputStream os = null;
            try {
                os = new FileOutputStream(file);
                String s = "我真" + i;

                try {
                    os.write(s.getBytes());
                } catch (NumberFormatException | IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
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