#How do I implement method add?

125 messages · Page 1 of 1 (latest)

teal gate
gloomy lightBOT
#

This post has been reserved for your question.

Hey @teal gate! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

molten sphinx
#

try it first

teal gate
#

i dont know where the method can be found

teal gate
molten sphinx
#

well, what's your input and output

teal gate
molten sphinx
#

close

#

that's more like your data

teal gate
#

[]

molten sphinx
#

the matrices themselves are the input

teal gate
#

these^

molten sphinx
#

what?

#

[] doesn't really mean anything on its own

teal gate
#

i meant the matrix yea

molten sphinx
#

so what should your output be

teal gate
#

hmmmmm

#

is my matrix also the output

#

?

#

im unsure

molten sphinx
#

yes

teal gate
#

okay good

molten sphinx
#

you get a matrix from adding 2 matrices

teal gate
#

yes i agree

molten sphinx
#

with "add" you don't want to be modifying the original matrices, so you'd need to have 3 separate matrices for the 2 inputs and 1 output

#

but that doesn't exist yet, so you need to make it

teal gate
#

okay

#

so i would need to create a new object?

molten sphinx
#

yeah

teal gate
#

what should i call it

molten sphinx
#

result, output, sum (since it's adding), something along those lines

#

just needs to match what it is

teal gate
#

something like this?

#

so i have created now three objects

molten sphinx
#

what

#

im so confused

teal gate
#

wait

molten sphinx
#

those types don't exist

teal gate
#

oh sorry

molten sphinx
#

the type needs to be a matrix, the same shape as the inputs

teal gate
#

so

#

now

#

i have created one matrix

molten sphinx
#

new output();
output doesn't exist

#

you're using output as a type here

#

you haven't created a matrix

#

do you know how to create arrays

teal gate
#

wait

#

the output

#

isn't that the name of the matrix?

#

im confused

molten sphinx
#
//                   v using as class
int[][] output = new output();
//      ^ using as variable
#

the class output doesn't exist

#

you need to create the matrix there

#

do you know how to create arrays

teal gate
#

oh it should be m2

teal gate
molten sphinx
#

yeah, you need to do that

teal gate
#

int intArray[]; right?

molten sphinx
#

no, that's the variable

#

creating the array itself

teal gate
#

int[] intArray = new int[]{ };

molten sphinx
#

matrices are just arrays of arrays, so you can't really use matrices if you don't know how to use arrays

molten sphinx
teal gate
#

yes okay

molten sphinx
#

but we don't know the values yet

#

so we can't use the {} format

teal gate
#

should i sett it to null

molten sphinx
#

how would you create an empty array of a given size

teal gate
#

?

molten sphinx
teal gate
#

okay should put zero

#

or you write size

molten sphinx
#

by empty here i mean it does have elements, but they aren't specified

teal gate
#

yes

molten sphinx
#

answer the question...

teal gate
#

i mean i learnt to write null

molten sphinx
#

it's not useful here. this is the thing you want to return

teal gate
#

then we dont write anything in it

#

we just usethis []

#

int[] intArray = new int[0];

#

do u mean this?

#

this is an empty array ----> int[] intArray = new int[0];

molten sphinx
#

right

teal gate
#

okay good

molten sphinx
#

by empty here i mean it does have elements but they aren't specified

#

so not a 0 length array

teal gate
#

sorry bro i didnt understand the question

molten sphinx
#

you need to create a matrix of the same size as the input matrices

teal gate
#

here is one

#

array

teal gate
#

?

molten sphinx
#

again, not zero elements

#

empty as in not specified

teal gate
#

not specified***

molten sphinx
#

you need to create a matrix with the same length as the input matrices

teal gate
#

hmmm i will try

#

int[][] intArray = new int[m1.length][m1[0].length];

#

is that correct?

molten sphinx
#

yep

teal gate
#

it dosen't work

#

soemthing is wrong

molten sphinx
#

that test looks really weird

#

your code looks fine thonkhave you reran it

teal gate
#

finally

teal gate
#

im sorry for being dumb sometimes

#

but thanks @molten sphinx

molten sphinx
#

oh wait i misunderstood

#

that's a weird way to do it, but i see what its going for now

teal gate
#

how do i close this channel?