求绝对值,注意打印的精度。
/** * 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)); } } }

本文介绍了一个简单的Java程序,该程序通过用户输入读取数值并计算其绝对值,同时使用了DecimalFormat确保输出的精度。
2333

被折叠的 条评论
为什么被折叠?



