Balloon Comes!
Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
The contest starts now! How excited it is to see balloons floating around. You, one of the best programmers in HDU, can get a very beautiful balloon if only you have solved the very very very... easy problem.
Give you an operator (+,-,*, / --denoting addition, subtraction, multiplication, division respectively) and two positive integers, your task is to output the result.
Is it very easy?
Come on, guy! PLMM will send you a beautiful Balloon right now!
Good Luck! Input
Input contains multiple test cases. The first line of the input is a single integer T (<T<) which is the number of test cases. T test cases follow. Each test case contains a char C (+,-,*, /) and two integers A and B(<A,B<).Of course, we all know that A and B are operands and C is an operator. Output
For each case, print the operation result. The result should be rounded to decimal places If and only if it is not an integer. Sample Input +
-
*
/ Sample Output - 0.50
package ACM1;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Scanner; public class hdu1 {
public static void main(String[]args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(); for(int i=0;i<n;i++)
{ String a = scanner.next();
int b = scanner.nextInt();
int c = scanner.nextInt();
//double result = (double)b/(double)c;
if(a.charAt(0)=='+')
System.out.println((b+c));
else if(a.charAt(0)=='-')
System.out.println((b-c));
else if(a.charAt(0)=='*')
System.out.println((b*c));
else
{
if(b%c==0)
System.out.println((b/c));
else
{
DecimalFormat dc = new DecimalFormat("0.00");
//dc.setMaximumFractionDigits(2);
//dc.setGroupingSize(0);
//dc.setRoundingMode(RoundingMode.FLOOR);
//System.out.println(dc.format(b/(1.0*c)));//我不明白为什么这个样子不对
System.out.format("%.2f",(b/(1.0*c)) ).println();//为什么这个样子对 } } } } }

Balloon Comes! hdu(小数位数处理)的更多相关文章

  1. C# decimal保留指定的小数位数,不四舍五入

    decimal保留指定位数小数的时候,.NET自带的方法都是四舍五入的. 项目中遇到分摊金额的情况,最后一条的金额=总金额-已经分摊金额的和. 这样可能导致最后一条分摊的时候是负数,所以自己写了一个保 ...

  2. oracle 取小数位数

    select ltrim('124532.62879'-floor('124532.62879'),'0.') from dual;select length(66695) from dual; 这两 ...

  3. 总结C#保留小数位数及百分号处理

    方法一: ); 方法二: Math.Round() 方法三: double dbdata = 0.55555; string str1 = dbdata.ToString("f2" ...

  4. double四舍五入,商品金额大小写转换,设置货币的小数位数跟格式输出,进制转化

      1:计算double值四舍五入的方法 对小数数值进行四舍五入,首先应该确认保留小数位, 如果数值的小数精度大于保留小数位,那么开始四舍五入计算.四舍五入的方法非常简单,在所有要丢失精度的小数位中加 ...

  5. js 四舍五入函数 toFixed(),小数位数精度

    js的加减乘除有时得到的结果的小数的位数非常大,这种结果非常难以读取,例如某两个数相乘得到的结果是:1.3921000000000001 这种结果小数的位数有点多,一般需要的结果是四舍无入的 1.39 ...

  6. alv中编辑的时候quan字段小数位数被截取掉

    alv中编辑的时候quan字段小数位数被截取掉:位数太多(最大只能为 0) 解决方法: ls_fcat-fieldname  =  'ZKBSL'.  ls_fcat-coltext  =  '卡板数 ...

  7. Java学习-047-数值格式化及小数位数四舍五入

    此小工具类主要用于数值四舍五入.数值格式化输出,很简单,若想深入研究,敬请自行查阅 BigDecimal 或 DecimalFormat 的 API,BigDecimal.setScale(位数,四舍 ...

  8. C#保留小数位数

    1.System.Globalization.NumberFormatInfo provider = new System.Globalization.NumberFormatInfo(); prov ...

  9. EL表达式取整数或者取固定小数位数的简单实现

    EL表达式取整数或者取固定小数位数的简单实现 例如${8/7} ,${6/7} ,${12/7 } 在页面的显示结果分别为: 1.1428571428571428 0.8571428571428571 ...

  10. openerp学习笔记 自定义小数精度(小数位数)

    小数位数标识定义: lx_purchase/data/lx_purchase_data.xml <?xml version="1.0" encoding="utf- ...

随机推荐

  1. eclipse maven安装配置

      下载在Apache下载Maven,下载地址:http://maven.apache.org/download.html,在win7下载文件为:apache-maven-3.1.0-bin.zip. ...

  2. Project Euler:Problem 41 Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  3. 可展开的UITableView (附源码)

    本文转载至 http://www.apkbus.com/forum.php?mod=viewthread&tid=137207&extra=page%3D1 由于工作需要,写了一个UI ...

  4. Node.js面试题

    Node.js面试题列表 什么是错误优先的回调函数? 如何避免回调地狱? 如何用Node来监听80端口? 什么是事件循环? 哪些工具可以用来保证一致的编程风格? 什么是测试金字塔?对于HTTP API ...

  5. 九度OJ 1156:谁是你的潜在朋友 (并查集)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5802 解决:2593 题目描述: "臭味相投"--这是我们描述朋友时喜欢用的词汇.两个人是朋友通常意味着他们存在着许多 ...

  6. 九度OJ 1047:素数判定 (素数)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9583 解决:4347 题目描述: 给定一个数n,要求判断其是否为素数(0,1,负数都是非素数). 输入: 测试数据有多组,每组输入一个数n ...

  7. 早一天把生意做到de

    const isMobilePhoneNum = (params) => { const areaCode = params.areaCode || 'cn' const str = param ...

  8. cocos2d-js v3.1的坑

    前几天因为要用到cc.pool,所以就换了v3.1版本,结果连生成apk的出错(cocos code ide), log显示为:error: relocation overflow in R_ARM_ ...

  9. 我的Java开发学习之旅------>Java NIO 报java.nio.charset.MalformedInputException: Input length = 1异常

    今天在使用Java NIO的Channel和Buffer进行文件操作时候,报了java.nio.charset.MalformedInputException: Input length = 1异常, ...

  10. mongoDB多级子文档查询

    db.getCollection('product').find({'coverage':{'$elemMatch':{'plan':{'$elemMatch':{'iscoverage':{'$in ...