Answers for "how to use an array in java"

13

java int array

int[] theNumbers = new int[5];

arr[0] = 4;
arr[1] = 8;
arr[2] = 15;
arr[3] = 16;
arr[4] = 23;
arr[5] = 42;
Posted by: Guest on February-18-2020
33

how to declare array java

int intArray[];    //declaring array
intArray = new int[20];  // allocating memory to array
//OR
int[] intArray = new int[20]; // combining both statements in one
Posted by: Guest on February-21-2020
7

Arrays in java

// Accessing array elements using for loop
public class AccessingArrayElements
{
   public static void main(String[] args)
   {
      int[] arrNum = {25, 23, 15, 20, 24};
      for(int a = 0; a < arrNum.length; a++)
      {
         System.out.println(arrNum[a]);
      }
   }
}
Posted by: Guest on November-25-2020
1

how to create an array in Java

//data_type[] variable_name = { "stuff", "stuff", stuff" }
String[] cars = {"car1", "car2", "car3"}

or
// data_type[] variable_name = new data_type[size]
int[] myNumbers = new int[3]
Posted by: Guest on October-07-2021

Code answers related to "how to use an array in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language