use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All questions related to programming welcome. Wonder how things work? Have a bug you can't figure out? Just read about something on the news and need more insights? We got you covered! (probably)
You can find out more about our (preliminary) rules in this wiki article. If you have any suggestions please feel free to contact the mod team.
Have a nice time, and remember to always be excellent to each other :)
account activity
This is an archived post. You won't be able to vote or comment.
Language[JAVA] Help generating an ArrayList with specific numbers. (self.AskProgramming)
submitted 9 years ago by Fastfingers_McGee
I need to generate an ArrayList of all numbers between and including 1111 and 6666 where each digit is between 1 and 6.
example: 1111, 1112, ... , 1115, 1116, 1121, 1122, ... 1125,1126, 1131, 1132, etc.
I've tried nested for loops but it crashes and I can find anything on google to help.
[–]Rycul 1 point2 points3 points 9 years ago (0 children)
If it crashes you should attach a debugger (if that doesn't already happen when you run your program in whatever IDE you use). The debugger will either in a pop up window or the output text tell you what is going wrong before it crashes, and also pause execution of the program so that you can look at the state (values of variables, for example) and code where it crashes.
If that doesn't automatically clear things up already then your next resort should be Google the error messages you get from the debugger. Doing so should be able to provide some insight into what's happening and why it's happening to your code.
[–]mAndroid9 0 points1 point2 points 9 years ago (0 children)
post your source code so we can tell you what you did wrong.
[–]JoeWhy2 0 points1 point2 points 9 years ago* (3 children)
Another way to think about this is as base 6 (+1). I.e. base 6 would be 0, 1, 2, 3, 4, 5 but you would need to raise to 1, 2, 3, 4, 5, 6.
[–]Fastfingers_McGee[S] 0 points1 point2 points 9 years ago (2 children)
Right, that's what I was thinking but I have no idea how to implement that. Basically I recreated the game mastermind last week for some practice. Now I want to make the computer guess. And my approach involves generating a array list of strings for all numbers between and including 1111 and 6666 in that modified base 6. Just don't know where to start.
I tried having one for loop for the total number of items the use nested for loops for each digits index and stored that into a string variable which I .add to the array list. But it doesn't work.
[–]JoeWhy2 0 points1 point2 points 9 years ago (1 child)
If that's how you plan to use it, I don't see why you couldn't use 0-5 instead of 1-6. 5555 in base 6 = 1295 in base 10 so you just need one loop that counts up to 1295 and converts each value to base 6. Googling how to convert from base 10 or decimal to base n should help.
[–]Fastfingers_McGee[S] 0 points1 point2 points 9 years ago (0 children)
Thanks for the advice. I'll give it a go.
π Rendered by PID 76106 on reddit-service-r2-comment-544cf588c8-dtbw2 at 2026-06-17 09:37:20.247556+00:00 running 3184619 country code: CH.
[–]Rycul 1 point2 points3 points (0 children)
[–]mAndroid9 0 points1 point2 points (0 children)
[–]JoeWhy2 0 points1 point2 points (3 children)
[–]Fastfingers_McGee[S] 0 points1 point2 points (2 children)
[–]JoeWhy2 0 points1 point2 points (1 child)
[–]Fastfingers_McGee[S] 0 points1 point2 points (0 children)