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. 【Atheros】无线网卡驱动性能测试工具pktgen的使用

    前言:从12年开始做无线驱动相关的工作,到13年大概做了一年半,现在歇了快一年了,以免白学那么久,最近重新整理了一下当时的资料,写一点文章,这方面的帖子比较少,当时碰到过很多问题难以解决,我是用的li ...

  2. HTML 学习笔记 JQuery(animation)

    动画效果也是JQuery库吸引人的地方,通过JQuery的动画方法,能够轻松的为网页天假非常紧菜的视觉效果. show()方法和hide()方法 show()方法和hide()方法是JQuery中最基 ...

  3. 响应式布局【3】 --- bootstrap

    本片文章主要讲解Bootstrap中如何实现响应式布局的. 参考资料&内容来源: https://code.ziqiangxuetang.com/bootstrap/bootstrap-gri ...

  4. Hadoop实战-Flume之Source regex_filter(十三)

    a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = ...

  5. 关联android-support-v4源码关联不上的解决办法

    在android项目中查看android-support-v4中的源码提示“Android Private Libraries which does not modified source attac ...

  6. Yii 框架 URL路径简化

    Yii 框架的訪问地址若不简化会让人认为非常繁琐.未简化的地址一般格式例如以下: http://localhost:80/test/index.php?r=xxx/xxx/xxx 若是带有參数会更复杂 ...

  7. linux下编译安装python

    从官网下载指定的源码包 https://www.python.org/downloads/source/ 把源码文件以二进制方式上传到linux服务器 安装python需要用到gcc工具,首先查看gc ...

  8. SSH Tunnel扫盲(ssh port forwarding端口转发)

    SSH的的Port Forward,中文可以称为端口转发,是SSH的一项非常重要的功能.它可以建立一条安全的SSH通道,并把任意的TCP连接放到这条通道中.下面仔细就仔细讨论SSH的这种非常有用的功能 ...

  9. js 事件委托 bug 修复

    下面是html 内容: <ul id="oul"> <li>1</li> <li>2</li> <li>3& ...

  10. iOS 多语言支持

    如果app将来面向国际化,比如说中国需要使用,美国也需要使用,此时就需要考虑app支持多国语言 具体方式如下 首先在Supporting Files中新建 Strings 起名: Localizabl ...