Home > Back-end >  Printf output format to do
Printf output format to do

Time:10-09

/* public class Main
{
Public static void main (String [] args)
{
//define some variables, which is used to format the output,
Double d=345.678;
String s="hello!" ;
Int I=1234;
"//" % "formatted output, after the" % "for the format of the content of the definition,
System. The out. Printf (" % f ", d); "//" f "formatting output floats,
System.out.println();
System. The out. Printf (" % 9.2 f, d);//in the "9.2" 9 said output the length of the 2 digits after the decimal point,
System.out.println();
System. The out. Printf (" % + 9.2 f, d);//"+" said output the number of plus or minus,
System.out.println();
System. The out. Printf (" % 9.4 f, d);//"-" said the number of output left-aligned (the default is right-aligned),
System.out.println();
System. The out. Printf (" % + 9.3 f, d);//"+ -" said output the number of plus or minus and left-aligned,
System.out.println();
System. The out. Printf (" % d ", I);//"d" said output decimal integer,
System.out.println();
System. The out. Printf (" % o ", I);//"o" said output octal integer,
System.out.println();
System. Out. Printf (" % x ", I);//"d" said output hexadecimal integer,
System.out.println();
System. The out. Printf (" % # x ", I);//"d" said output with hex logo integer,
System.out.println();
System. The out. Printf (" % s ", s);//"d" said output string,
System.out.println();
System. The out. Printf (" output a floating point number: % f, an integer: % d, a string: % s ", d, I, s);
//can output multiple variables, pay attention to order,
System.out.println(); */

  • Related