package java3;
import java.io.*;
class Thread1 extends Thread{
private String ID;
public static final String dizhi= "D:\\male.txt";
public Thread1(String ID) {
this.ID=ID;
}
public void run() {
String str=ID;
String sex=str.substring(8,10);
String ymd=str.substring(0,8);
int ymdi=Integer.parseInt(ymd);
while(ymdi<20190901&&sex.equals("00")) {
System.out.println(toString());
File file=new File(dizhi);
FileOutputStream fos;
byte[] b= new byte[1000];
try {
b=toString().getBytes();
fos = new FileOutputStream(file);
fos.write(b);
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("操作成功");
}
}
}
class Thread2 extends Thread{
private String ID;
public static final String dizhi1= "D:\\female.txt";
public Thread2(String ID) {
this.ID=ID;
}
public void run() {
String str=ID;
String sex=str.substring(8,10);
while(sex.equals("00")) {
File file1 =new File(dizhi1);
FileOutputStream fos;
byte[] b= new byte[1000];
try {
b=toString().getBytes();
fos = new FileOutputStream(file1);
fos.write(b);
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(toString());
System.out.println("操作成功");
}
}
}
public class Employee {
public String name;
public String ID;
public int age;
public String salary;
public Employee(String name,String ID,int age,String salary){
this.name=name ;
this.ID=ID;
this.age=age;
this.salary=salary;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID=ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name=name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age=age;
}
public String getSalary() {
return salary;
}
public void setSalary(String salary) {
this.salary=salary;
}
public String toString () {
String mess = " 姓名:" +getName()+" 年龄:"+getAge()+ " ID:"+getID()+ "薪水:"+getSalary() ;
return mess;
}
public static void main(String []args){
//ArrayList<Employee> arraylist=new ArrayList<Employee>();
Employee em[]=new Employee[10];
em[1] =new Employee("zengtao","2017010100222",22,"5800");
em[2] =new Employee("zengtao1","2017010100223",22,"5800");
em[3] =new Employee("zengtao2","2019010100232",22,"5800");
em[4] =new Employee("zengtao3","2019010101256",22,"5800");
em[5] =new Employee("zengtao4","2019010101256",22,"5800");
em[6] =new Employee("zengtao5","2019010100256",22,"5800");
em[7] =new Employee("zengtao6","2020010100289",22,"5800");
em[8] =new Employee("zengtao7","2019010200200",22,"5800");
em[9] =new Employee("zengtao8","2011010100212",22,"5800");
em[0] =new Employee("zengtao9","1999010100222",22,"5800");
System.out.println("hello world");
Thread1 th1;
th1 = new Thread1(em[1].getID());
for(int i=0;i<10;i++) {
th1 = new Thread1(em[i].getID());
th1.start();
//th1.run();
}
Thread2 th2;
for(int i=0;i<10;i++) {
th2 = new Thread2(em[i].getID());
th2.start();
// th2.run();
}
System.out.println("hell o");
}
}
错误代码java
猜你喜欢
转载自blog.csdn.net/qq_41814777/article/details/103647092
今日推荐
周排行