How to use Java system.out.printf ()

Source: Internet
Author: User

1  Packagetest; 2   3   4  Public classMain5 {  6      Public Static voidMain (string[] args)7     {  8         //define some variables that you can use to format the output. 9         DoubleD = 345.678; TenString s = "Hello!" ";  One         inti = 1234;  A         //"%" means the formatted output, and the content after "%" is defined as the format.  -System.out.printf ("%f", D);//"F" indicates the formatted output floating-point number.  - System.out.println ();  theSystem.out.printf ("%9.2f", D);//9 in "9.2" indicates the length of the output, and 2 indicates the number of digits after the decimal point.  - System.out.println ();  -System.out.printf ("%+9.2f", D);//"+" indicates the number of positive and negative numbers for the output.  - System.out.println ();  +System.out.printf ("%-9.4f", D);//"-" indicates the left-justified number of outputs (default is right-aligned).  - System.out.println ();  +System.out.printf ("%+-9.3f", D);//"+-" indicates the number of positive and left-aligned outputs.  A System.out.println ();  atSystem.out.printf ("%d", I);//"D" indicates an output decimal integer.  - System.out.println ();  -System.out.printf ("%o", I);//"O" indicates the output octal integer.  - System.out.println ();  -System.out.printf ("%x", I);//"D" indicates an output hexadecimal integer.  - System.out.println ();  inSystem.out.printf ("% #x", i);//"D" indicates the output of an integer with a hexadecimal flag.  - System.out.println ();  toSystem.out.printf ("%s", s);//"D" represents the output string.  + System.out.println ();  -System.out.printf ("Output a floating-point number:%f, an integer:%d, a string:%s", D, I, s);  the         //You can output multiple variables and note the order.  * System.out.println ();  $System.out.printf ("string: Hexadecimal number of%2$s,%1$d:%1$ #x", I, s); Panax Notoginseng         //"x$" represents the first few variables.  -     }   the}

How to use Java system.out.printf ()

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.