#Setting arrays equal to eachother

124 messages · Page 1 of 1 (latest)

urban stirrup
#

it returns int array

#

what do u want the method getsecretcode to return ?

toxic sphinx
#

i want it to return an array and then set it equal to code

urban stirrup
#

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

urban stirrup
#

make the int[] code like this int[][] code

toxic sphinx
#

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

urban stirrup
#

one sec

#

u did mistake

#

line 38 int[] code = new int[length];

#

it should be this

#

u are making new array

toxic sphinx
#

ok that fixed one error

#

now it says line 40 is wrong

urban stirrup
#

yes that i explianed up

urban stirrup
urban stirrup
toxic sphinx
#

yes

#

thats what the method does

#

the method works i just need to set that array of random numbers equal to a new array

urban stirrup
#

make code array two dimensional

#

yes i understood

#

ohh

#

so you have to crack the code[]

#

one sec

urban stirrup
toxic sphinx
#

ok that fixed it

#

do u know how i can print that code[] array?

urban stirrup
#

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");
}

urban stirrup
toxic sphinx
#

when i did System.out.println(Arrays.toString(code)); it printed the locations instead of numbers

urban stirrup
#

because 2 dimensional it is

toxic sphinx
#

oh

urban stirrup
#

it working now what u wanted?

toxic sphinx
#

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

urban stirrup
#

one set of numbers which is what?

#

just any random set of number?

toxic sphinx
#

yeah

#

like the first one for example

urban stirrup
#

int[] code = getsecretcode(rand,length);

#

remove all lines of code

#

this is enough

urban stirrup
#

removes the forloop

toxic sphinx
#

just a print issue now

#

just wanna make sure it equals the other one

urban stirrup
#

its toString

#

not TO

#

u have ide then just autocomplete

toxic sphinx
#

how come theyre not equal

#

thanks for everything so far btw youre the goat

#

if im asking too much just tell me lol

urban stirrup
#

if u want an equal array just return the same array lol ?

#

can u screenshot full file pls

toxic sphinx
#

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

west verge
#

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?

urban stirrup
toxic sphinx
#

yes it is from me and idk how to do that this my first time using an array ok @west verge

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

urban stirrup
#

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

toxic sphinx
#

it still returns 2 different arrays cuz its copying the method

#

instead of printing what the method prints

west verge
#

What? Show what you did

toxic sphinx
west verge
#

Dude...

#
int[] code = getsecretcode();
System.out.println(Arrays.toString(code));
System.out.println(Arrays.toString(code));
#

Here you go, same array

toxic sphinx
#

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[]

west verge
#

That's what I did above

#

Tell what isn't satisfactory

#

In simple and correct words, with an example

toxic sphinx
#

can i just call u dude

urban stirrup
west verge
urban stirrup
#

u can do array1 = array2

#

array1 will be set to value of array2

toxic sphinx
#

in my screenshot

#

System.out.println(Arrays.toString(getSecretCode(rand, length)));

#

returned a different array than

#

System.out.println(Arrays.toString(code));

#

I need

urban stirrup
#

yes because u are doing two times???

west verge
#

Yes. That's why you must not do that

#

Instead, do what I did

urban stirrup
#

ur calling 2 times

#

because its random

#

it wont be same everytime

toxic sphinx
#

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

west verge
#

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

toxic sphinx
#

im not complaining

#

you asked i explained

urban stirrup
west verge
#

Yes, well you explained that you need what we told you