Skip to content

Commit 2ae4512

Browse files
Add the SelfTest13 class
1 parent 3080f06 commit 2ae4512

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.guide.c5;
2+
3+
// Rewrite the MinMax class shown earlier so that it uses a for-each style for loop.
4+
public class SelfTest13 {
5+
public static void main(String[] args) {
6+
int[] nums = {99, -10, 100123, 18, -978, 5623, 463, -9, 287, 49};
7+
8+
int min, max;
9+
10+
min = max = nums[0];
11+
12+
for (int x : nums) {
13+
if (x < min) min = x;
14+
if (x > max) max = x;
15+
}
16+
17+
System.out.println("min and max: " + min + " " + max);
18+
}
19+
}

0 commit comments

Comments
 (0)