Java Array problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

18th Feb 2021, 3:57 AM
WTF [•_•]
WTF [•_•] - avatar
10 Answers
+ 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();
18th Feb 2021, 7:51 AM
Ollie Q
Ollie Q - avatar
+ 1
Thanks
19th Feb 2021, 6:22 AM
WTF [•_•]
WTF [•_•] - avatar
+ 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
19th Feb 2021, 6:54 AM
WTF [•_•]
WTF [•_•] - avatar
+ 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
19th Feb 2021, 7:23 AM
Ollie Q
Ollie Q - avatar
+ 1
Ollie Q ohh No problem man, I'll get back when I'm through with it. Thanks for your time :)
19th Feb 2021, 12:59 PM
WTF [•_•]
WTF [•_•] - avatar
+ 1
no problem • WTF [•_•] • let me know if you have any more problems. happy coding
19th Feb 2021, 8:27 PM
Ollie Q
Ollie Q - avatar
0
no problem • WTF [•_•] • happy coding
19th Feb 2021, 6:47 AM
Ollie Q
Ollie Q - avatar
0
Ollie Q ok thanks man 😊
24th Feb 2021, 9:49 AM
WTF [•_•]
WTF [•_•] - avatar
17th Apr 2021, 2:37 AM
Emmanuel Manu
Emmanuel Manu - avatar
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
25th Aug 2021, 6:06 PM
William Davis
William Davis - avatar