Here I have written the logic for generating customer id but how can I preserve the value of i
so that when next time function is called i=11
instead of i=10
. Whenever I am running this it is starting from i=10
everytime.
public class TestId {
public static void main(String[] args) {
String start = "CUST";
String total = "";
int i = 10;
if (10 <= i && i < 100) {
total = start + "000" + i;
i++;
} else {
if (i <= 100 && i < 1000) {
total = start + "00" + i;
i++;
} else {
if (i <= 1000 && i < 10000) {
total = start + "0" + i;
i++;
} else {
total = start + i;
i++;
}
}
}
System.out.println(total);
}
}