正在回答 回答被采纳积分+1
package jihe;
public class Employee {
private int id;
private String name;
private double salary;
public Employee(int id, String name, double salary) {
super();
this.id = id;
this.name = name;
this.salary = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String toString() {
return name+" "+salary;
}
}
===============================================================================
package jihe;
import java.util.ArrayList;
import java.util.List;
public class LIST {
public static void main(String[] args) {
List<Employee> list=new ArrayList<Employee>();
Employee one=new Employee(1,"张三",5000);
Employee two=new Employee(2,"李四",5500);
Employee three=new Employee(3,"赵六",4000);
list.add(one);
list.add(two);
list.add(three);
System.out.println("员工姓名"+" "+"员工薪资");
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}
for(Employee stu: list);{
System.out.println(stu);
}
int a[]= {1,2,3,4,5,};
for(int b:a) {
System.out.print(b);
}
}
}
为什么用增强型for循环输出stu的时候报错!
- 参与学习 人
- 提交作业 5461 份
- 解答问题 7238 个
此次推出的专题为Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始学习Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星