码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2003 求绝对值

时间:2017-05-08 23:08:03      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:opened   mat   tle   pen   while   format   esc   problem   sys   

 

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);
        }
    }
}
View Code

 

HDU 2003 求绝对值

标签:opened   mat   tle   pen   while   format   esc   problem   sys   

原文地址:http://www.cnblogs.com/hey-man/p/6828036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!