Can someone help me with a code that generates all the possible four digit PIN between 0000 and 9999 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help me with a code that generates all the possible four digit PIN between 0000 and 9999

15th Mar 2019, 3:23 PM
Karabo K. Tebelelo
Karabo K. Tebelelo - avatar
3 Answers
+ 17
● run a loop for a from 0 to 9999 ● see (a+"").length() , if it is k, then add (4-k) zeores before printing a //one more idea if not want to get into length(), Strings etc, just use conditions like <10, <100 & <1000 to know number of digits in number & add zeroes in front accordingly [but will become tiring work to write code if the pin will be of high number of digits so it would be better to make code working for any general number of digits].
15th Mar 2019, 4:54 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
- generate integers from 0 to 9999 (use a for loop) - convert to String - left pad with zeroes
15th Mar 2019, 3:56 PM
Tibor Santa
Tibor Santa - avatar
+ 3
for(int i = 0 ; i <=9999 ; i++) { System.out.printf("%04d\n",i); }
17th Mar 2019, 2:37 AM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar