forked from bhagat-hrishi/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray1.java
More file actions
39 lines (27 loc) · 1.21 KB
/
array1.java
File metadata and controls
39 lines (27 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class array1
{
public static void main(String [] args)
{
//1:At the time of array creation compulsory we should specify the size
// int [] a=new int[];//C.E:array dimension missing
//2:It is legal to have an array with size zero in java.
int[] b=new int[0];
System.out.println(b.length);//0
//3:If we are taking array size with -ve int value then we will get runtime exception
int[] c=new int[-3];//R.E:NegativeArraySizeException
//4:Only allowed data type for array decleration are (byte,short,char,int) and other are NOT allowed
int[] d=new int['a'];//(valid)
byte bite=10;
int[] a2=new int[bite];//(valid)
/*long used*/int[] a3=new int[10l];//C.E:possible loss of precision//(invalid)
/*double used*/int[] a4=new int[10.5];//C.E:possible loss of precision//(invalid)
//declare 2 2D arrays
int [][] tmp1,tmp2;
tmp1=new int[2][3];
tmp2=new int[3][4];
//here tmp3 is 2D array but tmp4 is 1D array
int []tmp3[],tmp4;
tmp3=new int[2][3];
tmp4=new int[3][4];//Error assigning 2D array to 1D array
}
}