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-徐少伟1407094216 #28

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

java1-徐少伟1407094216 #28

MeerkatX opened this issue Dec 25, 2015 · 0 comments

Comments

@MeerkatX
Copy link

//作业一删除羊:
ArrayList sheeplist=new ArrayList();
sheeplist.add(new sheep("aa"));
sheeplist.add(new sheep("bb"));
sheeplist.add(new sheep("cc"));
sheeplist.add(new sheep("dd"));
sheeplist.add(new sheep("ee"));
//方法一:
for (int i = 0; i <=sheeplist.size();i++) {
sheeplist.remove(0);
}
//方法二:
for(int i=5;i>2;i--)
sheeplist.remove(sheeplist.get(i));

//循环:
for (int j = 0; j < sheeplist.size(); j++) {
System.out.println(((sheep)sheeplist.get(j)).getName());
}
//作业2:
public class main {
public static void main(String[] args) throws IOException{
File file=new File("D:\helloworld.txt");
File filebox=new File("d:\test");
if(!filebox.exists())
filebox.mkdir();
for (int j = 0; j < 10; j++) {
file=new File(filebox,"helloworld"+j+".txt");
try {
if(!file.exists())
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String s="zzzz"+j;
OutputStream out=new FileOutputStream(file);
out.write(s.getBytes());
}
InputStream in=new FileInputStream(file);
byte[] b=new byte[5];
in.read(b);
String s2=new String(b);
System.out.println(s2);
//作业3:
class ExThread extends Thread{
public ExThread(String name){
super(name);
}
public ExThread(){
super();
}
public void run() {
for(int i=0;i<5;i++){
System.out.println("ExThread"+this.getName()+i);
}
}

}

class Threadi implements Runnable{

public String name;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public void run() {
for(int i=0;i<5;i++){
System.out.println("runable"+this.getName()+i);
}
}
}

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