Computer Science, asked by ddiya5920, 1 year ago

Create an anonymous array in java?

Answers

Answered by RAJUtheSAVER
0
class AnonymousArray

{

static void print(int a[])

{

  for(int i=0;i<a.length;++i)

   System.out.print(a[i]+" ");

}

 

static void print(int a[][])

{

  for(int i=0;i<a.length;++i)

  {

   for(int j=0;j<a[i].length;++j)

    System.out.print(a[i][j]+" ");

 

   System.out.println("");

  }

}

  

public static void main(String...s)

{

  //1d anonymous array

  print(new int[]{10,20,30,40});

 

  System.out.println("n");

  

  //2d anonymous array

  print(new int[][]{{10,20},{30,40},{50,60}});  

}

}

Answered by Oreki
2

We can create an Anonymous Array in Java by the following syntax,

new data_type[ ] {elementOne, elementTwo, elementThree, ...}

Similar questions