-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysConcept.java
More file actions
72 lines (57 loc) · 1.56 KB
/
Copy pathArraysConcept.java
File metadata and controls
72 lines (57 loc) · 1.56 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.CoreJava;
import java.util.Arrays;
public class ArraysConcept {
public static void main(String[] args) {
// TODO Auto-generated method stub
// limitations of array:
// 1.size is fixed
// 1. with new keyword:
int a[] = new int[4];
a[0] = 10;
a[1] = 20;
a[2] = 30;
a[3] = 40;
System.out.println(a[0]);
System.out.println(a[3]);
// System.out.println(a[4]);//ArrayIndexOutOfBoundsException
// System.out.println(a[-1]);//ArrayIndexOutOfBoundsException
int len = a.length;// 4
System.out.println(len);
int hi = len - 1;
System.out.println(hi);
int li = 0;
System.out.println(li);
System.out.println("--------");
// to print all the values from the array: use for loop:
for (int i = 0; i < len; i++) {
System.out.println(a[i]);// 10 20 30 40
}
// without using for loop:
System.out.println(a);// [I@c2e1f26
System.out.println(Arrays.toString(a));
// double array:
double d[] = new double[2];// 0 to 1
d[0] = 12.33;
d[1] = 34.44;
System.out.println(d[0] + d[1]);
// String array:
String emp[] = new String[3]; // 0-2
emp[0] = "Pooja";
emp[1] = "Ravi";
emp[2] = "Robin";
System.out.println("total emp: " + emp.length);
System.out.println(Arrays.toString(emp));
for (int k = 0; k < emp.length; k++) {
System.out.println(emp[k]);
if (emp[k].equals("Ravi")) {
System.out.println("ravi salary is : " + 1000);
break;
}
}
}
//static array ex:
//month/days
//200
//250
//
}