Problem Description
求实数的绝对值。
Input
输入数据有多组,每组占一行,每行包含一个实数。
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
Sample Input
123
-234.00
Sample Output
123.00 234.00
分析:此题考绝对值函数
AC源代码(Java语言):
import java.util.Arrays; import java.util.Scanner; public class Main{ // public final static double pi = 3.1415927; public static void main(String[] args) { Scanner sin=new Scanner(System.in); while(sin.hasNextDouble()){ double num = sin.nextDouble(); num = Math.abs(num); String res = String.format("%.2f", num); System.out.println(res); } } }
时间: 2024-07-29 00:33:17