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();//为什么这个样子对 } } } } }

最新文章

  1. Webstorm+Webpack+echarts构建个性化定制的数据可视化图表&amp;&amp;两个echarts详细教程(柱状图,南丁格尔图)
  2. 微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013)
  3. 更新证书错误:No matching provisioning profiles found
  4. VMware 安装CentOS7.0
  5. 【原创】Kakfa message包源代码分析
  6. C# 开发者代码审查清单【转】
  7. C#版本的历史
  8. UVALive 6263 The Dragon and the knights --统计,直线分平面
  9. MVC4相关Razor语法以及Form表单
  10. 《C#高级编程》之泛型--1创建泛型类
  11. 数往知来 ASP.NET 表单的提交_url传值_重定向 &lt;十八&gt;
  12. confirm的用法
  13. Dialog与FragmentDialog源代码分析
  14. Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error
  15. java 并发工具类CountDownLatch &amp; CyclicBarrier
  16. PHP导出生成CSV文件
  17. Java实现一个简单的循环队列
  18. 将html前端代码提取公因数(5)
  19. eclipse+pyDev
  20. Python的time和datetime

热门文章

  1. 【demo练习四】:WPF用户控件案例
  2. 深入Asyncio(七)异步上下文管理器
  3. TP 接收post请求使用框架自带函数I()防止注入
  4. js异步请求发展史和yield
  5. wamp环境配置;转自发瑞的博客(www.cnblogs.com/cyrfr/p/6483529.html)
  6. 九度OJ 1005:Graduate Admission (排序)
  7. mac sublime text 3 add ctags plugin
  8. 我的Android进阶之旅------>温习Sqlite3的常用操作
  9. POJ3984 迷宫问题【水BFS】
  10. [BZOJ 1095] [ZJOI 2007]Hide 捉迷藏