如何找到 的 最小和最大元素。ArrayListBigIntegers
我尝试过的是:
import java.math.BigInteger;
import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args){
BigInteger i1 = new BigInteger("4343345345345");
BigInteger i2 = new BigInteger("4343453345345345");
BigInteger i3 = new BigInteger("4343453345");
List<BigInteger> list = new ArrayList<>();
list.add(i1);
list.add(i2);
list.add(i3);
BigInteger max = list.stream().max(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
BigInteger min = list.stream().min(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
System.out.println(max.intValue());
System.out.println(min.intValue());
}
}
但这给了我以下错误:
HelloWorld.java:20: error: ')' expected
BigInteger min = list.stream().min(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
^
HelloWorld.java:20: error: ';' expected
BigInteger min = list.stream().min(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
^
HelloWorld.java:20: error: illegal start of expression
BigInteger min = list.stream().min(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
^
HelloWorld.java:20: error: ';' expected
BigInteger min = list.stream().min(Comparator.comparing(BigInteger::intValue())).orElseThrow(NoSuchElementExcep::new);
^
还有其他想法吗?
温温酱
侃侃无极
森林海
相关分类