自动递增的序列号


import java.text.DecimalFormat;

public class Exec {

	public static void main(String[] args) {
		Customer c1 = new Customer();
		System.out.println("客户ID: " + c1.getCustomerId());
		Customer c2 = new Customer();
		System.out.println("客户ID: " + c2.getCustomerId());
		Customer c3 = new Customer();
		System.out.println("客户ID: " + c3.getCustomerId());
		Customer c4 = new Customer();
		System.out.println("客户ID: " + c4.getCustomerId());
		Customer c5 = new Customer();
		System.out.println("客户ID: " + c5.getCustomerId());
	}

}

class Customer{
	private static int totalCount = 0;
	private int customerID;
	
	public Customer() {
		++totalCount;
		customerID = totalCount;
		System.out.println("来了一位客户");
	}

	public String getCustomerId() {
		DecimalFormat df = new DecimalFormat("0000000000");
		return df.format(customerID);
	}
}

你可能感兴趣的:(java)