-2

So in a class called Test2 there's a method that is

public static int[] number(int[] numbers) {
    System.out.println(numbers);
    return numbers;
{

And then in Main

Test2.number(?)

What do I write in the "?" so I can list some numbers and print them?

2
  • create a array and pass it and you can simply do this Test2.number(new int[] {1, 2, 3}) Commented Dec 4, 2020 at 6:37
  • 1
    Does this answer your question? pass array to method Java Commented Dec 4, 2020 at 6:41

2 Answers 2

1

You just have to create an array. Please have a look for how to work with Java arrays in any search engine.

Test2.number(new int[]{1, 2, 3});

You could also change the signature of number() to take varargs to use just some numbers as parameter.

public static int[] numberVarargs(int...numbers)

Use it with:

Test2.number(1, 2, 3);
Test2.number(new int[]{1, 2, 3}); // using an array is still valid
Sign up to request clarification or add additional context in comments.

Comments

0

no but you can print integer arrays,

int[] numArray = {1,2,3,4,5,6,7,8};
 Test2.number(numArray);

if you want to insert numbers instead of arrays change:

public static int[] numbers (int[] numbers){
} 

to

public static int numbers (int numbers){

}

if you have any further problems please reply to this answer

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.