The difference between the use of print, println, printf's


The difference between print, println, printf's

  • print output does not wrap, only one parameter, the cursor is positioned at the last character of the line

    int a=10;
    System.out.print("哈哈");
    System.out.print(a);

  • println with similar print output but wrap, only one parameter, the cursor is positioned at the beginning of the next line

int a=10;
int b=2;
System.out.println("哈哈");
System.out.println(a);

  • printf output does not wrap, the cursor is positioned at the last character string of the line, for printing formatted

    Can not directly output the basic data types, you specify a formatting rule to use it.

int a=10;
int b=2;
System.out.printf("哈哈");
System.out.printf("haha,%d,%d",a,b);

Printf formatted string of source code for use in a method

 

Guess you like

Origin www.cnblogs.com/Yhh-449/p/12662642.html