-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray1.java
More file actions
71 lines (58 loc) · 1.51 KB
/
Array1.java
File metadata and controls
71 lines (58 loc) · 1.51 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
public class Array1
{
// var arg
public static void sum(int... a)
{
int total = 0;
for(int x1:a)
{
total = total+x1;
}
System.out.println("sum:"+total);
}
// public static void sum(int x,int y)
// {
// System.out.println(x+y);
// }
// public static void sum(int x,int y,int z)
// {
// System.out.println(x+y+z);
// }
public static void main(String[] args)
{
// 1D arrays declaration in three ways
// int a[];
// int []a;
// int[] a;
// int[] a={1,2,3,4,5};
// System.out.println(a[1]);
// int[][] a=new int[3][2];
// Jagged arrays
// int[][] a=new int[3][];
// a[0] = new int[1];
// a[1] = new int[3];
// a[2] = new int[4];
// System.out.println(a.length);
// System.out.println(a[0].length+a[1].length+a[2].length);
// int[] a[]=new int[][];
// length vs length()
// normal arrays
// int a[] = {1,2,3,4,5,6,7,8,9,10};
// add(a);
// ANONYMOUS ARRAYS
// add(new int[]{1,2,3,4,5,6,7,8,9,10,11,12});
// Varaible argument methods
sum(1,2,3);
sum(1,2,3,4,5);
sum(1,2,3,4,5,6,7,8);
}
// public static void add(int[] a)
// {
// int total = 0;
// for(int x1:a)
// {
// total = total+x1;
// }
// System.out.println("sum:"+total);
// }
}