1.精确四舍五入用DecimalFormat
DecimalFormat df = new DecimalFormat("#.0");
System.out.print(df.format(ans));
2.数组求和用stream
int sum = Arrays.stream(nums).sum();
3.nextLine
输入是
1
hello world
如果nextInt+nextLine连着用,nextLine会先读第一行的换行符。所以正确的应该是
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
sc.nextLine();
String s = nextLine();
4.函数式接口
new Thread(()->{}).start();
new PriorityQueue<>((a,b)->(a-b));