Balloon Comes! hdu(小数位数处理)
2024-09-08 06:26:00
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();//为什么这个样子对 } } } } }
最新文章
- Webstorm+Webpack+echarts构建个性化定制的数据可视化图表&;&;两个echarts详细教程(柱状图,南丁格尔图)
- 微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013)
- 更新证书错误:No matching provisioning profiles found
- VMware 安装CentOS7.0
- 【原创】Kakfa message包源代码分析
- C# 开发者代码审查清单【转】
- C#版本的历史
- UVALive 6263 The Dragon and the knights --统计,直线分平面
- MVC4相关Razor语法以及Form表单
- 《C#高级编程》之泛型--1创建泛型类
- 数往知来 ASP.NET 表单的提交_url传值_重定向 <;十八>;
- confirm的用法
- Dialog与FragmentDialog源代码分析
- Fix Windows 7 Msvcp71.dll And Msvcr71.dll Missing Error
- java 并发工具类CountDownLatch &; CyclicBarrier
- PHP导出生成CSV文件
- Java实现一个简单的循环队列
- 将html前端代码提取公因数(5)
- eclipse+pyDev
- Python的time和datetime
热门文章
- 【demo练习四】:WPF用户控件案例
- 深入Asyncio(七)异步上下文管理器
- TP 接收post请求使用框架自带函数I()防止注入
- js异步请求发展史和yield
- wamp环境配置;转自发瑞的博客(www.cnblogs.com/cyrfr/p/6483529.html)
- 九度OJ 1005:Graduate Admission (排序)
- mac sublime text 3 add ctags plugin
- 我的Android进阶之旅------>温习Sqlite3的常用操作
- POJ3984 迷宫问题【水BFS】
- [BZOJ 1095] [ZJOI 2007]Hide 捉迷藏