Hi, I am a beginner in JAVA language...
I am making a simple sudoku game (in notepad -I have to use only notepad).
I have my sudoku tables stored in 2d arrays e.g sudoku1[9][9].
Lets say I have 5 2d-arrays, sudoku1....sudo ku5, and I want a random one to be chosen... how do I do that.
I know I have to use class Random, but how do I make it in this case (i.e 2d arrays)??
also
this is how u put values in a 2d array...
int [][] example2d=
{
{0, 3, 2},
{0, 5, 8},
};
how can u put values in a 3d array??
int [][][] example3d=
???????
10 2016 Ganon11 3,652
Recognized Expert Specialist
Are the different sudoku values in several different files, or all in the same file?
To input into a 3d array... -
int my3DArray = { { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} },
-
{ {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
-
{ {19, 20, 21}, {22, 23, 24}, {25, 26, 27} } }
I am a beginner, I am not sure about what you mean by filing them (I mean as a java programmer)... I have them stored like this... - int [][] sudok1=
-
{
-
{3, 5, 9, 8, 7, 1, 6, 4, 2},
-
{1, 2, 4, 3, 6, 9, 7, 5, 8},
-
{8, 6, 7, 2, 5, 4, 9, 1, 3},
-
{5, 8, 3, 1, 4, 7, 2, 9, 6},
-
{2, 9, 1, 6, 3, 8, 5, 7, 4},
-
{7, 4, 6, 5, 9, 2, 8, 3, 1},
-
{6, 7, 5, 4, 8, 3, 1, 2, 9},
-
{4, 1, 8, 9, 2, 5, 3, 6, 7},
-
{9, 3, 2, 7, 1, 6, 4, 8, 5},
-
};
-
int [][] sudok2=
-
{
-
{3, 5, 9, 8, 7, 1, 6, 4, 2},
-
{1, 2, 4, 3, 6, 9, 7, 5, 8},
-
{8, 6, 7, 2, 5, 4, 9, 1, 3},
-
{5, 8, 3, 1, 4, 7, 2, 9, 6},
-
{2, 9, 1, 6, 3, 8, 5, 7, 4},
-
{7, 4, 6, 5, 9, 2, 8, 3, 1},
-
{6, 7, 5, 4, 8, 3, 1, 2, 9},
-
{4, 1, 8, 9, 2, 5, 3, 6, 7},
-
{9, 3, 2, 7, 1, 6, 4, 8, 5},
-
};
Is there a way of putting them into a file and extracting them?
I get this error for the 3d one you posted... - P1.java:17: illegal initializer for int
-
int my3DArray = { { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} },
For the randoming I came with the idea of putting all 2d arrays (sudoku1 & sudoku2 in this case) in a 3d one. Thus using - Random ran = new Random();
-
sudok[ran.nextInt(2)];
...I will be able to extract a random 2d array.
Is that good, or is there a better way to do it?
Ganon11 3,652
Recognized Expert Specialist
Ahh...sorry, I had read your question wrong and thought you were storing the sudoku puzzles in a text file. Go ahead and ignore that first line :)
Yes, creating a 3d array like that should work...I wonder if you can initialize it like this: - int[][] sudoku1 = { /* blah blah blah here... */ };
-
int[][] sudoku2 = { /* blah blah blah here too... */ };
-
// ...and so on...
-
int[][][] sudokus = {sudoku1, sudoku2, /* blah blah blah... */ };
P.S.:
I got the 3d array working (...forgot about [][][])
- int[][] sudoku1 = { /* blah blah blah here... */ };
-
int[][] sudoku2 = { /* blah blah blah here too... */ };
-
// ...and so on...
-
int[][][] sudokus = {sudoku1, sudoku2, /* blah blah blah... */ };
Can I do something like this... - int [][][] sudokus = { { {sudok1} },
-
{ {sudok2} } };
... I mean do I have to retype the whole 2d arrays again, isn't there a way to reference to them.
Ganon11 3,652
Recognized Expert Specialist
Well, if sudok1 and sudok2 are already 2d arrays, then you can't set them to the third 'array' of sudokus. You wouldn't have to retype the 2d arrays - you said you already had them declared in your program, yes? Then just initialize sudokus using those variables.
ok I guess I can do that...
Would it be possible (and also more efficient) to store&retrieve sudokus in a text file??
P.S: THANKS for all the help!
Ganon11 3,652
Recognized Expert Specialist
It definitely would be possible to store the sudokus in a text file. It would also allow you to (relatively) easily add more puzzles to be used in your program. Whether it's more efficient, though, is something I'm not sure of. I know it would take longer to open the file and read the numbers into your arrays. Whether that extra flexibility in adding puzzles is worth the added loading time is up to you.
But if I put them in a text file will I be able to retrieve a random table (pull randomly a whole 2d array).
I mean now that I have put them in a 3d one I can choose a random one. - my3DArray[ran.nextInt(3)][][]
I guess I have to first learn how the text file retrieving works.
also
how can the "user" store (meaning to store while the program is runned)?
How can that value stay permanently?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Virus |
last post by:
Ok well what I am trying to do is have
1.) the background color to change randomly with 5 different colors.(change
on page load)
2,) 10 different quotes randomly fadeing in and out in random spots on the
webpage. with a delay timer on them, so they keep changing as the page is
open. Not random each time the page is loaded.
If anyone can help it would be greatly appreaciated, I have tried many of
|
by: titi |
last post by:
Question
The road and traffic authority for a small country currently uses a
system to store information about all 'currently' licensed drivers.
A licensed driver has the following info stored about them in a
record;
1. Given name(s) of the license holder.(not more than 128 char (may
have spaces)).
2. Surname of the license holder.(Not more then 128 same like above).
|
by: bb91915 |
last post by:
I am taking a beginners class in C and am attempting to write code for
extra problems my instructor gave us. These are not for grade and are
only used solely for practice. I have a hard time taking pseudocode
and turning it into code. Since I am in a beginners class, we have
only learned so much to date, so what I am presenting will be really
rough, so please pardon my ignorance.
Here are my instructions, with my code to follow:
...
|
by: Michael Fitzpatrick |
last post by:
Transferring arrays from C DLL's to VB.Net
I have a DLL written in C. This DLL reads a text file and creates a several
very large arrays, 500,000 points and even larger. I would like the get the
data in VB.Net so that I can plot it. Presently I am creating an equally
sized array in VB and copying the data from the DLL's array into the VB
array.
There must be a better way. I looked into using a SAFEARRAY but it looks to
me that VB.Net...
|
by: MC |
last post by:
Good Morning
Anyone know any good lessons online about Arrays in vb.net.
I am a hobbiest and stuggling to understand Arrays. Let me explain briefly
what I want to do.
I am writing a Poker Solutions Program purely for my oen fun and want to
shuffle a deck of cards. now the easiest way, i think, is to make an Array
that looks like this:
| |
by: aaragon |
last post by:
Hello everybody,
I appreciate your taking the time to take a look at this example. I
need some help to start the design of an application. To that purpose
I'm using policy-based design. The idea is to have a Class that stores
elements of Class2 in different ways (arrays in stack memory, arrays in
heap memory, using the std::vector and so on). I would like the user
to customize the creation of a class with Class2 and StoragePolicy like...
|
by: Bigj0410 |
last post by:
i've been trying to figure out these questions and i can't seem to understand them...can anyone help?
1)Write a full program in C++ that creates the two-dimensional randomArray
array with 10 rows and 10 columns, and fills it with random numbers
respectively: the first row with random number in range [1, 100), the second
row with random number in range [100, 200), …, the 10th row with random
number in range [900, 1000), The program then...
|
by: wokeup2sleep |
last post by:
im a beginner at comp science, and my prof is using python, which is totally new tom me i had a few questions with the program im writing, im having a few problems.
brief summary
i have to do a project where there are nine boxes filled with number 1-8, and 1 space is empty, the game needs to be scrambled, also all the moves need to be saved. the game can be paused anytime during thegame. the object is to move the numbers into the black spot...
|
by: Leroymetzker |
last post by:
//My card class
import java.util.Arrays;
import java.util.Random;
public class Card
{
//Attributes
private int suit;
private int value;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |