Skip to main content

Posts

Showing posts with the label array

java array

Array:- Array is special type of variable which can store multiple values into a single variable but all the values must be same. In java array is object. How to use array:- 1.      Declaration of array 2.      Create array Syntax for array declaration:- type arrayname[]; Or type []arrayname; For example int a[];  or int[]a; Create array:- a=new int[5];  or int a[]=new int[5]; or int []a=new int[5]; Example1:ArraY.java class ArraY { public static void main(String[]args) { int []a; a=new int[5]; System.out.println("length of array is : "+a.length); } } Output:- C:\JAVATECH>javac ArraY.java C:\JAVATECH>java ArraY length of array is : 5 Example2:- ArraY.java class ArraY { public static void main(String[]args) { int []a; a=new int[5]; System.out.println("length of array is : "+a.length); System.out.println("Array elements are : "); for(int i=0...