Challenge ProgrammingProgramDesign Competition Training Manual-1.6.3Travel(The trip)
Import Java. text. decimalformat; public class problem_the_trip {/*** @ Param ARGs */public static void main (string [] ARGs) {double [] parts = {15.00, 15.01, 3.00, 3.01}; // double [] rows = {10.00, 20.00, 30.00}; string result = string. valueof (caculate (random, double. parsedouble (AVG (cost); // first obtain the average AVG, and then calculate the amortized cost result = result. substring (0, result. indexof (". ") + 3); // truncates the operation result to two digits after the decimal point. out. print (result); // The minimum total output transaction amount} Private Static string AVG (double [] average) {// calculate the average value of double sum = 0; For (INT I = 0; I <strong. length; I ++) {sum = sum + hour [I];} double AVG = sum/hour. length; decimalformat df = new decimalformat ("0.000"); // specify the format, retain three decimal places // system. out. println (DF. format (avg); Return DF. format (avg); // returns results with three decimal places} Private Static double caculate (double [] Random, double avg) {// system. out. println (avg); double avgmoney = 0; // The minimum total transaction amount; double tempjudge = 0; // determine the amount of expenditure and income, double in = 0; // double out = 0; // record the payment for (INT I = 0; I <strong. length; I ++) {tempjudge = tempjudge + (avg-Token [I]); // The amount of money received is negative. // If (then [I]-AVG> = 0) {// The overpay in = in + then [I]-AVG; // money for statistics} else {// out = out + AVG-income [I]; // money for statistics} If (tempjudge> = 0) {// pay back more avgmoney = In; // The minimum total transaction amount based on the income} else {// Add more avgmoney = out; // pay-as-you-go for expenditure} // decimalformat df = new decimalformat ("0.00"); // system. out. println (avgmoney); // system. out. println (DF. format (avgmoney); Return avgmoney; // The output settlement value is the minimum total transaction amount }}