Formatting

Formatting - mileage, "...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Output the calculated values for US Standards. System.out.println(String.format("\nOriginal Odometer Reading " + "Final Odometer Reading Fuel Used Mileage")); System.out.println(String.format("% 15d% 28d% 19.1f gal% 14.2f " + "mpg\n\n",intOrigMilage,intFinalMilage, dblGallonsUsed, dblMPG)); Marcus Toms //Display results (printf to format to two/one decimal place/s.) System.out.println("\nOriginal Odometer Reading Final Odometer Reading Fuel Used Mileage"); System.out.printf(" " +start + " " + end + " %.1f gal %.2f mpg\n\n ", fuel, mpg); System.out.println("\nOriginal Odometer Reading Final Odometer Reading Fuel Used Mileage"); System.out.printf(" " +start_km + "km " + end_km + " km %.2f liters %.2f km/l ", fuel_liters, kml);; }//end main Chris Cunanan System.out.format("\n\n%30s %27s %13s %19s\n", "Starting Odometer Reading", "Ending Odometer Reading", "Gas Usage", "Mileage");//Formats headers for information System.out.format("%20d %28d %20.1f %4s %12.2f %4s\n\n", odoStart, odoEnd, gasUsage, " gal",
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: mileage, " mpg");//Formats and prints data System.out.format("\n%30s %27s %13s %19s\n", "Starting Odometer Reading", "Ending Odometer Reading", "Gas Usage", "Mileage"); System.out.format("%20.0f %28.0f %20.1f %7s %9.2f %5s", odoStartMetric, odoEndMetric, gasUsage, " liters", mileage, " km/L"); }//end main() R Grice. DecimalFormat fmt = new DecimalFormat ("0.##"); System.out.println("Original Odometer Reading\tFinal Odometer " + "Reading\tFuel Used\tMileage"); System.out.println("\t "+startMiles+"\t\t\t"+endMiles+ " \t\t"+fmt.format(gallonsUsed)+" gal\t"+fmt.format(mpg)+ " mpg"); System.out.println(); System.out.println("Original Odometer Reading\tFinal Odometer " + "Reading\tFuel Used\tMileage"); System.out.println("\t "+startKilometers+"\t\t\t"+endKilometers+ "\t\t "+fmt.format(litersUsed)+" ltr "+fmt.format(kpl)+ " kpl"); Patrick McCarley...
View Full Document

Page1 / 2

Formatting - mileage, "...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online