#How do I implement method add?
125 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @teal gate! Please use
/closeor theClose Postbutton 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.
try it first
i dont know where the method can be found
where do i even start
well, what's your input and output
so my input is inside these matrix right?
[]
the matrices themselves are the input
these^
i meant the matrix yea
so what should your output be
yes
okay good
you get a matrix from adding 2 matrices
yes i agree
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
yeah
what should i call it
result, output, sum (since it's adding), something along those lines
just needs to match what it is
yes sir
something like this?
so i have created now three objects
wait
these are the names, you asked what should you call it
those types don't exist
oh sorry
the type needs to be a matrix, the same shape as the inputs
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
// 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
oh it should be m2
yes
yeah, you need to do that
int intArray[]; right?
int[] intArray = new int[]{ };
matrices are just arrays of arrays, so you can't really use matrices if you don't know how to use arrays
right, that's one way to do it
yes okay
should i sett it to null
how would you create an empty array of a given size
?
no, that's useless here
.
by empty here i mean it does have elements, but they aren't specified
yes
answer the question...
i mean i learnt to write null
it's not useful here. this is the thing you want to return
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];
right
okay good
by empty here i mean it does have elements but they aren't specified
so not a 0 length array
sorry bro i didnt understand the question
okay got it
you need to create a matrix of the same size as the input matrices
so do you mean i should create multiple arrays with zero elements
?
not specified***
you need to create a matrix with the same length as the input matrices
hmmm i will try
int[][] intArray = new int[m1.length][m1[0].length];
is that correct?
yep
thank you so much
im sorry for being dumb sometimes
but thanks @molten sphinx
no don't do this
oh wait i misunderstood
that's a weird way to do it, but i see what its going for now
good
how do i close this channel?
have you reran it