java求助。。。大侠帮忙找找错误
public class Customer {
int custNo=0;
int point=0;
}
public class CustManager {
Customer[] customers = new Customer[100];
public void add(Customer cust){
for(int i=0;i<customers.length;i++){
if(customers[i]==null){
customers[i]=cust;
break;
}
}
}
public void show(){
System.out.println("编号\t积分");
for(int i=0;i<customers.length;i++){
if(customers[i]==null)
break;
System.out.println(customers[i].custNo+"\t"+customers[i].point);
}
}
}
import java.util.Scanner;
public class TestCustomer {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Customer cust=new Customer();
CustManager custm=new CustManager();
for(int j=0;j<100;j++){
System.out.print("请输入会员编号:");
cust.custNo=sc.nextInt();
System.out.print("请输入会员积分:");
cust.point=sc.nextInt();
custm.add(cust);
if(cust.point==0)
break;
}
custm.show();
}
}
当积分输入为0时,退出输入,显示输入的卡号和积分、、、
输出错误结果:
[解决办法]
for(int j=0;j<100;j++){
Customer cust=new Customer();
System.out.print("请输入会员编号:");
cust.custNo=j;
System.out.print("请输入会员积分:");
cust.point=j+1;
custm.add(cust);
custm.show();
if(cust.point==0)
break;
}