-3

I am working on a basic Java app. I want to assign an ID to each person. The ID should contain 10 digits. for example: 0000000001 0000000002

how should I set my count

  private static int count= 0;
  private int id;
  private String Name;
Sarah
  • 19
  • 1

1 Answers1

1

Just change your id to String and then calculate it in constructor using String.format()

String id = String.format("%010d", count);

where first "0" in "%010d" tells method to pad given in argument number with zeros, and "10" is a length of the result.