-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?

Entl
  • 11
  • 1
  • create a array and pass it and you can simply do this `Test2.number(new int[] {1, 2, 3})` – deadshot Dec 04 '20 at 06:37
  • 1
    Does this answer your question? [pass array to method Java](https://stackoverflow.com/questions/1610757/pass-array-to-method-java) – Sudhir Ojha Dec 04 '20 at 06:41

2 Answers2

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
Milgo
  • 2,617
  • 4
  • 22
  • 37
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