FormattingDecimalNum

FormattingDecimalNum - //Line 6...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//Program to illustrate how to format the output of //decimal numbers. / public class FormattingDecimalNum { public static void main (String[] args) { double x = 15.674; //Line 1 double y = 235.73; //Line 2 double z = 9525.9864; //Line 3 System.out.println("Line 4: Outputting the values of " + "x, y, and z with two decimal " + "places."); //Line 4 System.out.printf("Line 5: x = %.2f %n", x); //Line 5 System.out.printf("Line 6: y = %.2f %n", y);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //Line 6 System.out.printf("Line 7: z = %.2f %n", z); //Line 7 System.out.println("Line 8: Outputting the values of " + "x, y, and z with three decimal " + "places."); //Line 8 System.out.printf("Line 9: x = %.3f %n", x); //Line 9 System.out.printf("Line 10: y = %.3f %n", y); //Line 10 System.out.printf("Line 11: z = %.3f %n", z); //Line 11 } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Ask a homework question - tutors are online