print Statement
There are three kind of print statements
- System.out.print(Argument);
- System.out.println(Argument);
- System.out.printf(format , Argument);
print and println
Type this code and See the out put
public class PrintStatement {
public static void main(String[] args) {
System.out.print("One , ");
System.out.print("Two , ");
System.out.print("Three , ");
}
}
The Out put is One , Two , Three ,
The print("One") method instead prints just the One , but does not move the cursor to a new line
Now open your .java file and change your code like this and save and see the out put
class PrintStatement {
public static void main(String[] args) {
System.out.println("One , ");
System.out.println("Two , ");
System.out.println("Three , ");
}
}
The Out put is
One ,
Two ,
Three ,
The Diferent of print and println is
The println("") method prints the string "" and moves the cursor to a new line. The print("") method instead prints just the string "", but does not move the cursor to a new line. Hence, subsequent printing instructions will print on the same line. The println() method can also be used without parameters, to position the cursor on the next line
a
No comments:
Post a Comment