Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis0
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 Respostas
+ 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