-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayDemo1.java
68 lines (32 loc) · 1.1 KB
/
ArrayDemo1.java
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
public class ArrayDemo1
{
public static void main(String[] args)
{
// There are 3 techniques for populating an array
// -------technique #1----------------------------------
int[] grades = {90,86,100,73,85};
// -------technique #2----------------------------------
int[] numbers = new int[4];
numbers[0] = 5;
numbers[1] = 7;
numbers[2] = 14;
numbers[3] = -6;
// -------technique #3----------------------------------
int size=0;
System.out.print("how many ages will you enter?");
size=SavitchIn.readLineInt();
int[] ages = new int[size];
for(int i = 0; i <= ages.length-1; i++)
{
System.out.print("Enter someone's age: ");
ages[i] = SavitchIn.readLineInt();
}
////////////////////////////////////////////////////////////////
// use a for loop to display an array:
for(int i = 0; i < ages.length; i++)
{
System.out.println("\nAge # " + i + ": " + ages[i]);
}
System.out.println("\n\n\n");
}
}