Yamineko
-10
Q:

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]);
      }
   }
}
3
//method 1
int[] age = new int[3];
        age[0] = 1;
        age[1] = 3;
        age[2] = 6;

        for (int i=0; i < 3; i++)
            System.out.println(age[i]);

//method 2
        int[] num = {3,3,5};
        //int num[] = {3,3,5}; also works the same

        System.out.println(num[0]);
13
For example: int[ ] num = new int[6];
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]);
      }
   }
}
3
//Metodo 1
type nome = new type[n];

//Metodo 2
type nome[];
nome = new type[n];
3
int[] intArray = new int[20];
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
4
int[] arr;			// Declaration dataType can int, float etc.
arr = new int[N];	// Allocation N = 0 to 2,147,483,647.
6
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars[0] = "Opel";
System.out.println(cars[0]);
// Now outputs Opel instead of Volvo
7
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
23
type nome[] = new type[n];
1
 int[] intArray = new int[]{ 1,2,3,4,5,6,7,8,9,10 }; 
 // Declaring array literal
0

New to Communities?

Join the community