We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
1.删除后三只羊 int num = sheepList.size(); System.out.println("从后向前删:"); for(int i = num - 1;i >= num - 3;i --){ sheepList.remove(i); } for(Object s:sheepList){ System.out.println(((Sheep)s).name); } System.out.println("从前向后删"); for(int i = 0;i < num - 3;i ++){ sheepList.remove(0); }for(Object s:sheepList){ System.out.println(((Sheep)s).name); } System.out.println("foreach:"); int i = 0; for(Object s:sheepList){ if(i >= 3){ sheepList.remove(((Sheep)s).name); }else{ System.out.println(((Sheep)s).name); } i ++; } Iterator it = sheepList.iterator(); System.out.println("通过迭代器遍历:"); for(int i = num - 1;i > num - 3;i --){ if(i <= 3){ sheepList.remove(i); } while(it.hasNext()){ Sheep csn = (Sheep)it.next(); System.out.println(csn.name); } } 2.自动写文件 public static void main(String[] args) throws IOException{ //创建目标文件 File Demo = new File("e://YQ"); if(!Demo.exists()){ Demo.mkdir(); } for(int i = 0;i < 10;i ++){ File file = new File("e://YQ//yq" + i + ".txt"); if(!file.exists()){ file.createNewFile(); } } String[] filenames = Demo.list(); for(int i = 0;i < filenames.length;i ++){ FileOutputStream fos = new FileOutputStream("e://YQ//yq" + i + ".txt"); String s = "我真" + i; fos.write(s.getBytes()); fos.close(); System.out.println("第" + i + "次写入完成"); } } 3.线程实现方法继承Thread与接口Runnnale的区别 public static void main(String[] args) { //数据独立,其数值分别为3,2,1 Threadexend person1 = new Threadexend("关公"); Threadexend person2 = new Threadexend("秦琼"); person1.start(); person2.start(); //对象唯一,数据共享,数值一共是3,2,1 IThread person3 = new IThread(); new Thread(person3,"奥特曼").start(); new Thread(person3,"小怪兽").start(); } static class Threadexend extends Thread{ public Threadexend(String name){ super(name); } public Threadexend(){ super(); } private int nuqi = 3; public void run(){ for(int i = 1;i <= 3;i ++){ if(nuqi > 0){ System.out.println(getName() +"第" + i + "次打了对方" + "," + "剩余怒气值" + nuqi--); } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: