the//print does not wrap and the println has a line wrap feature. Example: Uprint.javaclass uprint{
public static void Main (String arg[])
{
int i,j,k;
for (i=1;i<10;i++)
{
System.out.println ();
for (j=1;j<=i;j++)
{
K=i*j;
System.out.print (i+ "*" +j+ "=" +k+ "");
}
}
}
}
Print , Println , Printf the Difference
Related definitions:
Print: Displays the information in the Command window, and the output cursor is positioned after the last character;
Println : Displays the information in the Command window, and the output cursor is positioned at the beginning of the next line;
Printf: The information is formatted in the Command window, and the output cursor is positioned after the last character , It comes from C language, the function that produces the formatted output (from stdio.h medium);
Related differences:
Print with the Println the only difference :P rint After the output information is not wrapped, Println After the output of the message is automatically wrapped;
Print ("\ n") = Println (""), that System.out.print ("asd\n"); = System.out.println ("ASD");
Note: when copied to the output stream, these sequences cause their related actions to be displayed on devices that have this capability:
\ \ Backslash \a warning \b backspace \f page break \ n line break \ r enter \ t Jump \v vertical Jump-grid \DD D DDD is a 1, 2, or 3-bit octal number. These escape sequences are displayed as bytes with numeric values specified by the octal number.
Related Demos ( Assuming that the file is e:/a folder under ):
Print
A.java The text file reads the following code:
Class a{
public static void Main (string[] args) {
System.out.print ("a");
System.out.print ("a");
}
}
The results are as follows:
Aa
Println
B.java The text file reads the following code:
Class b{
public static void Main (string[] args) {
System.out.println ("B");
System.out.println ("B");
}
}
The results are as follows:
B
B
Printf
Type definition:
Character |
Input data type |
Meaning |
D, I |
Int |
Signed 10 binary number, I is a vintage notation |
O |
unsigned int |
Unsigned 8 binary number |
U |
unsigned int |
Unsigned 10 binary number |
X, X |
unsigned int |
unsigned 16 binary, x abcdef,x with abcdef to represent the number of 10~15 |
F |
Double |
Decimal |
E, E |
Double |
Scientific notation represents the number, the case of which is denoted by the case of "E" |
G, G |
Double |
Using the shortest form of the two above, the case is used with%e and%e |
C |
Char |
Converts the input number to the corresponding character |
S, s |
char *, wchar_t * |
String |
P |
void * |
Output pointers in 16 binary form |
N |
int * |
Until this character, the total number of characters output, do not output text |
% |
Do not enter |
The output character "%" itself |
Note:%g,%g in the number of decimal places four bits or exponent greater than equal precision with%E,%E, otherwise%f.
C.java The text file reads the following code:
Class c{
public static void Main (string[] args) {
int a = 1;
Double b = 2;
System.out.printf ("%d", a);
System.out.println ();
System.out.printf ("%f", b);
System.out.println ();
System.out.printf ("%.2f", b);
}
}
The difference between print, println, and printf