forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestNumbers.java
More file actions
executable file
·38 lines (36 loc) · 1.3 KB
/
LargestNumbers.java
File metadata and controls
executable file
·38 lines (36 loc) · 1.3 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
/* */ package ch13;
/* */ import java.math.BigDecimal;
/* */ import java.math.BigInteger;
/* */ import java.util.ArrayList;
/* */
/* */ public class LargestNumbers {
/* */ public static void main(String[] args) {
/* 8 */ ArrayList<Number> list = new ArrayList<>();
/* */
/* 10 */ list.add(Integer.valueOf(45));
/* 11 */ list.add(Double.valueOf(3445.53D));
/* */
/* 13 */ list.add(new BigInteger("3432323234344343101"));
/* */
/* 15 */ list.add(new BigDecimal("2.0909090989091343433344343"));
/* */
/* 17 */ System.out.println("The largest number is " +
/* 18 */ getLargestNumber(list));
/* */ }
/* */
/* */ public static Number getLargestNumber(ArrayList<Number> list) {
/* 22 */ if (list == null || list.size() == 0) {
/* 23 */ return null;
/* */ }
/* 25 */ Number number = list.get(0);
/* 26 */ for (int i = 1; i < list.size(); i++) {
/* 27 */ if (number.doubleValue() < ((Number)list.get(i)).doubleValue())
/* 28 */ number = list.get(i);
/* */ }
/* 30 */ return number;
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch13/LargestNumbers.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/