Java 计算机程序设计
发布网友
发布时间:2022-04-22 04:59
我来回答
共4个回答
热心网友
时间:2023-10-04 20:40
package com.test;
import java.util.Vector;
import com.domain.Employee;
public class MyVector {
public static void main(String[] args) {
// 创建对象数组,大小为5
Employee[] employee = new Employee[5];
employee[0] = new Employee("NO1", "Tom", 4000);
employee[1] = new Employee("NO2", "Sherry", 4400);
employee[2] = new Employee("NO3", "Rose", 3600);
employee[3] = new Employee("NO4", "Smith", 5600);
employee[4] = new Employee("NO5", "Mary", 4680);
// 创建向量
Vector<Employee> employeeVector = new Vector<Employee>();
// 循环添加员工对象到向量中
for (int i = 0; i < employee.length; i++) {
employeeVector.add(employee[i]);
}
System.out.println("编号\t姓名\t工资");
// 遍历,输出数据
for (Employee emp : employeeVector) {
System.out.print(emp.getsNo() + "\t");
System.out.print(emp.getsName() + "\t");
System.out.println(emp.getSalary());
}
}
}
热心网友
时间:2023-10-04 20:41
package com.cainiaoqi;
import java.util.ArrayList;
import java.util.Iterator;
class Employee{
private String sNo;
private String sName;
private double salary=0;
Employee(String id,String name,double salary){
sNo=id;
sName=name;
this.salary=salary;
}
public void output(){
System.out.println("编号:"+sNo+",姓名:"+sName+",薪水:"+salary);
}
}
public class Test5 {
public static void main(String[] args) {
ArrayList<Employee> list = new ArrayList<Employee>(5);
list.add(new Employee("NO1", "Tom", 4000));
list.add(new Employee("NO2", "Sherry", 4400));
list.add(new Employee("NO3", "Rose", 3600));
list.add(new Employee("NO4", "Smith", 5600));
list.add(new Employee("NO5", "Mary", 4680));
Iterator<Employee> it = list.iterator();
while(it.hasNext()){
it.next().output();
}
}
}
热心网友
时间:2023-10-04 20:41
在电脑上输入java然后下载然后安装就行了
热心网友
时间:2023-10-04 20:42
需要合作开发吗?