#Setting arrays equal to eachother
124 messages · Page 1 of 1 (latest)
i want it to return an array and then set it equal to code
code[i] will return an int because its an array 1 dimensinal
and u are saying code[i] should be equal to another array in line 40 intarrayis not equal to int
oh i thinks o u need to make a 2d array
make the int[] code like this int[][] code
u think so? i just need to rename the array from the method to another name
idk how cuz im a beginner at this clearly lmao
ill try tht
one sec
u did mistake
line 38 int[] code = new int[length];
it should be this
u are making new array
yes that i explianed up
there were 2 erros
u basically want an arrays of array of random numbers right?
yes
thats what the method does
the method works i just need to set that array of random numbers equal to a new array
make code array two dimensional
yes i understood
ohh
so you have to crack the code[]
one sec
but u already have to code array why are u adding random numbers then
System.out.println(Arrays.toString(code));
if u want to check two arrays are equal to (Arrays.isequal(code,code2));
if(Arrays.equals(code,code2))
{
System.out.println("both is equal");
}
if its more 1 dimensional then do
System.out.println(Arrays.deepToString(code));
when i did System.out.println(Arrays.toString(code)); it printed the locations instead of numbers
because 2 dimensional it is
do this
oh
it working now what u wanted?
my problem now is that it is returning[[7, 1, 0, 3], [9, 7, 9, 7], [0, 0, 1, 0], [3, 6, 4, 4]]
instead
i just need one set of numbers
like only 7 1 0 3
int[] code = getsecretcode(rand,length);
remove all lines of code
this is enough
how come theyre not equal
thanks for everything so far btw youre the goat
if im asking too much just tell me lol
if u want an equal array just return the same array lol ?
can u screenshot full file pls
yea
everytime i set it equal it just runs the loop again instead of setting the new array equal to the output of the loop in the method
Put your array in a variable
Is any of this code from you? How is it possible you did all that and you don't understand variables?
random.nextint just reutrns an random int
yes it is from me and idk how to do that this my first time using an array ok @west verge
Well arrays, like all other values, can be put in variables
In fact you put an array in a variable in your method getSecretCode()
Just do that again to store the array generated by getSecretCode()
Generating a random array is a rather weird first time using arrays
int[] code = getsecretcode();
System.out.println(Arrays.toString(code));
if u need to use multiple times one opjet just store it
that way ur code will be effiencient
it still returns 2 different arrays cuz its copying the method
instead of printing what the method prints
What? Show what you did
Dude...
int[] code = getsecretcode();
System.out.println(Arrays.toString(code));
System.out.println(Arrays.toString(code));
Here you go, same array
no
i need whatever getsecretcode prints to be the same as code[]
i just dont know how to set equal the output of getsecretcode to another array code[]
That's what I did above
Tell what isn't satisfactory
In simple and correct words, with an example
can i just call u dude
just return the same array?
Why do people always ask that? Voice doesn't work. Write
in my screenshot
System.out.println(Arrays.toString(getSecretCode(rand, length)));
returned a different array than
System.out.println(Arrays.toString(code));
I need
yes because u are doing two times???
this is just calling one time
ur calling 2 times
because its random
it wont be same everytime
lemme explain this project
its a number guessing game
getsecretcode generates a random number
the user needs to guess
then
i am going to have to evaulate how many correct digits the user guessed ONLY USING code[] and an array that the user guessed.
so
getsecretcode cant run again
the final result of that method just has to be equal to code[]
i hope that expalins it
Yes, and that's exactly what we've showed you
Stop complaining and do as we said. You'll notice this is what you asked all along
did u tried what he said?
Yes, well you explained that you need what we told you