java - generate a random number for a credit card -
java - generate a random number for a credit card -
i trying utilize method generate credit card number of 16 digits starts 4 if issuersymbol equals issuer amer express. random number has start 3 if issuersymbol equals issuer visa , 5 it issuer master card.
public integer getissuercode(string issuersymbol){ int randominteger = 0; random random = new random(); for(int = 0; < 5; i++) { randominteger = random.nextint(); if (issuersymbol.equals(issuer_amer_express)) { } else { system.out.println("error"); } if(issuersymbol.equals(issuer_visa)){ } else{ system.out.println("error"); } if (issuersymbol.equals(issuer_master_card)){ } else{ system.out.println("error"); } } homecoming randominteger; }
i think have problem if , else. need understand go in else if if not true code should changed them if else if , else ...
if (issuersymbol.equals(issuer_amer_express)) { } else if(issuersymbol.equals(issuer_visa)){ } else if (issuersymbol.equals(issuer_master_card)){ } else { system.out.println("error"); }
another suggestion random
class includes nextint(int)
(per javadoc) *returns pseudorandom, uniformly distributed int
value between 0 (inclusive) , specified value (exclusive), drawn random number generator's sequence.
randominteger = 3 + random.nextint() % 3;
or
randominteger = 3 + random.nextint(3);
this ensure randominteger in 3 or 4 or 5
java java-ee
Comments
Post a Comment