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. JS常用方法手记

    1.判断arr数组是否含有元素str,没有返回-1 arr.indexOf(str) 2.遍历arr数组,k为键,v为值 arr.map((v, k) => { return;}) 3.arr数 ...

  2. TP框架部分---空控制器

    <?php namespace Admin\Controller; use Think\Controller; class DengLuController extends Controller ...

  3. Mybatis的配置文件和映射文件详解

    一.Mybatis的全局配置文件 1.SqlMapConfig.xml是mybatis的全局配置文件,配置内容如下: properties(属性) settings(全局配置参数) typeAlias ...

  4. Entity Framework 4.1:多对多的关系

    这篇文章讨论多对多的关系. 让我们从最简单的例子开始.我们让 EF4.1 来推断表的映射.我在订单和雇员之间建模多对多的关系. )] publicstring CustomerName { get; ...

  5. 随机生成指定长度的密码之---Random

    随机生成指定长度的密码思路: 1.密码中可能包含字母,数字,特殊符号,为了区别分别定义常量 2.随机生成密码,自然想到要用到java.util.Random 类 3.定义一个带两个参数的方法,1跟2, ...

  6. BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器

    BZOJ3878: [Ahoi2014&Jsoi2014]奇怪的计算器 Description [故事背景] JYY有个奇怪的计算器,有一天这个计算器坏了,JYY希望你能帮助他写 一个程序来模 ...

  7. pinpoint本地开发-web模块

    web模块中的前端依赖会导致工程很难打包成功,对于这些,我们可以直接注释掉 比如: <plugin> <groupId>com.github.eirslett</grou ...

  8. java和js互调 拨打电话

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  9. iOSapp内跳转到设置界面

    从app内跳转到设置界面的代码如下: NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIAp ...

  10. Algorithm: Sieve of Eratosthenes

    寻找比n小的所有质数的方法. 2是质数, 2*i都是质数,同样3是质数,3*i也都是质数 代码如下 int n; vector<, true); prime[] = prime[] = fals ...