0
Java Array problem
How do I make a sudoku like program in java(not the game) just to creat an array of 3x3 dimensions that fills the rows and columns with random numbers. IMPORTANT: the numbers must no repeat itself.
10 ответов
+ 3
hi • WTF [•_•] •
here is how you’d make a 3x3 array..
int[ ][ ][] sample = { {1, 2, 3}, {4, 5, 6}, {7,8,9}};
then you’d just need to use the random function in java
java.util.Random
Random random = new Random();
return random.ints(min, max)
.findFirst()
.getAsInt();
+ 1
Thanks
+ 1
Ollie Q same dude, to fill the array automatically I need a for bucle but how do i make sure the numbers being generated doesnt repeats itself? If possible using math.random
+ 1
hi • WTF [•_•] •
check out this code...
https://code.sololearn.com/cbxUC4d1T4eh/?ref=app
you’ll just have to alter the if condition so that it can iterate throught 3.
sorry for the slow response i accidental wrote the code in javascript before i remeber you need java
+ 1
Ollie Q ohh No problem man, I'll get back when I'm through with it. Thanks for your time :)
+ 1
no problem • WTF [•_•] •
let me know if you have any more problems.
happy coding
0
no problem • WTF [•_•] •
happy coding
0
Ollie Q ok thanks man 😊
0
https://code.sololearn.com/cU1SZM1IJVan/?ref=app
Hi i hope this helps
0
Maybe you could make an if statement to test if the next number matches any of the other numbers?
Example: After telling it to pick a number, then put,
if(!sample[2] == sample[1]){
input code } else [
pick new number
}
I don't know, i'm learning as well, but it works in my mind lol