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)