#why won’t this run?

25 messages · Page 1 of 1 (latest)

idle zinc
#

I keep getting errors and I’m a little confused as to why it won’t run:

public class MyProgram
{
public static void main(String[] args)
{
remover(a={1,2,3,4,5});
}
public static int[] remover(int[]a)
{
int [] b={2,3,4,5};
for(int i=0;i<b.length;i++)
{
b[i]=a[i+1];
}
return b;
}
}

When i return b, is it meant to be b[] instead of just b?

brazen scrollBOT
#

This post has been reserved for your question.

Hey @idle zinc! 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.

analog chasm
#

no

#

what error are you getting

#

ah

#

i see

#

the problem is with remover(a={1,2,3,4,5});

#

that's not how you create arrays, nor how you pass parameters

#

java's parameters are all positional, so name = is never used

#

when you create an array, unless it's directly for a variable, you have to specify the type, so you have to use new int[]{ ... }

#

(or make a separately and then just pass a)

#

it would help to read or at least show your error

idle zinc
#

oh yeah sorry!

idle zinc
analog chasm
#

??? you haven't though

idle zinc
#

ohhhh wait

#

i see

#

okay

analog chasm
#

a is never initialized anywhere in your code

idle zinc
#

ok got it i see now

analog chasm
#

it's declared as a parameter in remover, but it doesn't exist in main

idle zinc
#

yesss

#

tysm !