Arrays | Java: Arrays are using for storing the multiple same data type values.
Syntax: int[] a = {1, 2, 3};
int[] b = new int[n]; where n is the size of an array.
Here is the Code:
- import java.io.*;
- class Main {
- public static void main (String[] args) {
- int[] a = {1, 2, 3};
- System.out.println(a[2]);
- for(int i=0;i<a.length;i++)
- {
- System.out.println(a[i]);
- }
- int[] b = new int [5];
- for(int i=0;i<b.length;i++)
- {
- b[i]=5;
- System.out.println(b[i]);
- }
- }
- }
Output:
3
1
2
3
5
5
5
5
5
Here is the Video: