我需要打开一个包含整数的文本文件,我需要打印出文件中最小和最小的数字

时间:2016-03-10 17:29:51

标签: java

这是我到目前为止所得到的。我不知道如何在屏幕上打印最低和最高的数字。任何帮助将不胜感激。谢谢。

DECLARE @aracct VARCHAR(12)
SET @aracct = '49944928'
DECLARE @tran_id_pmt VARCHAR(6)
SET @tran_id_pmt = '147317'
SELECT '''',CONVERT(VARCHAR(8), transactions.item_no) AS item_no,'''','' FROM receivables_pmt INNER JOIN transactions
           ON receivables_pmt.tran_id_paid = transactions.tran_id
                WHERE aracct = @aracct AND tran_id_pmt = @tran_id_pmt
                    ORDER BY transactions.item_no


item_no       
---- -------- ---- ----
'    1003     ',    
'    1006     ',   
'    1010     ',  
'    1012     ', 

}

1 个答案:

答案 0 :(得分:2)

使用Java 8:

final Path path = Paths.get("LABEX10.txt");
try (Stream<String> lines = Files.lines(path)) {
    final LongSummaryStatistics summary = lines
            .mapToLong(Long::parseLong)
            .summaryStatistics();
    System.out.printf("range [%d .. %d]%n", summary.getMin(), summary.getMax());
}

这种方法比proposed duplicate更现代。