-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForEach.java
More file actions
61 lines (60 loc) · 1.71 KB
/
Copy pathForEach.java
File metadata and controls
61 lines (60 loc) · 1.71 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
//Nancy
public class ForEach
{
public static void main (String [] args){
String [] arr = {"dog", "cat", "horse", "cow", "pig"};
for (int i = 0; i < 5; i++){
System.out.print(arr[i] + " ");
}
System.out.println();
for (String n : arr){
System.out.print(n + " ");
}
System.out.println();
for (int i = 4; i >= 0; i--){
System.out.print(arr[i] + " ");
}
System.out.println();
for (int i = (arr.length-1); i >= 0; i--){
int k = (arr.length - 1) - i;
String temp = arr[i];
arr[i] = arr[k];
arr[k] = temp;
}
for (int i = 4; i >= 0; i--){
System.out.print(arr[i] + " ");
}
int [] nums = new int [10];
for (int i = 0; i < 10; i++){
nums[i] = (int) (Math.random() * 50) + 1;
}
System.out.println();
for (int x : nums){
System.out.print(x + " ");
}
System.out.println();
int sum = 0;
for (int y : nums){
sum += y;
}
System.out.println ("Sum: " + sum);
System.out.println ("Average: " + (double) sum / 10);
int min = nums[0];
for (int z : nums){
if (z < min){ min = z;}
}
System.out.println ("Min: " + min);
int count = 0;
for (int a : nums){
if (a > 25){ count++;}
}
System.out.println ("Over 25: " + count);
boolean [] ft = new boolean [10];
for (int i = 0; i < 10; i++){
if (i % 2 != 0){ ft[i] = true;}
}
for (boolean b : ft){
System.out.print(b + " ");
}
}
}