Balloon comes! HDU (number of decimal digits processing)

Source: Internet
Author: User

Balloon comes!Time Limit: -/ +MS (java/others) Memory Limit:65536/32768K (java/Others) Total submission (s):5402Accepted Submission (s):1722Problem DescriptionThe Contest starts now! How excited it isTo see balloons floating around. One of the best programmersinchHDU, canGetA very beautiful balloonifOnly you have solved the very very very ... easy problem. Give Youoperator(+,-, *,/--denoting addition, subtraction, multiplication, division respectively) and both positive integers, your task isTo output the result. Is it very easy?Come on, Guy! PLMM would send you a beautiful Balloon right now!Good Luck!Inputinput contains multiple test cases. the first line of the input isA single integer T (0<T< +) which isThe number of test cases. T test Cases follow. Each test CaseContains aCharC (+,-, *,/) and integers A and B (0<A,B<10000). Of course, we all know this A and B are operands and C isAnoperator. Outputfor each Case, print the operation result. The result should is rounded to2 decimalPlaces If and onlyifIt isNot an integer. Sample Input4+1 2-1 2*1 2/1 2Sample Output3-120.50 
 PackageACM1;ImportJava.math.RoundingMode;ImportJava.text.DecimalFormat;ImportJava.util.Scanner; Public classHDU1 { Public Static voidMain (String[]args) {Scanner Scanner=NewScanner (system.in); intn =Scanner.nextint ();  for(inti=0;i<n;i++) {String a=Scanner.next (); intb =Scanner.nextint (); intc =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=NewDecimalFormat ("0.00"); //dc.setmaximumfractiondigits (2); //dc.setgroupingsize (0); //Dc.setroundingmode (Roundingmode.floor);  //System.out.println (Dc.format (b/(1.0*c)));//I don't understand why this is not the way it is.                        System.out.format ("%.2f", (b/(1.0*c))  . println ();//Why does this look right } }                            }                                }            }

Balloon comes! HDU (number of decimal digits processing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.