求绝对值,注意打印的精度。
/** * Created by YangYuan on 2017/12/8. */ public class Problem2003 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); DecimalFormat df = new DecimalFormat("0.00"); while (scanner.hasNext()) { double x = scanner.nextDouble(); if (x < 0) x = -x; System.out.println(df.format(x)); } } }