Second simple program in java
println():
println() method shows the text as it is on the screen which is provided in println() method, which is followed by a new line. The cursor goes to the next line.
print() method shows the text as it is on the screen which is provided in print() method, which is not followed by a new line. The cursor is still on the same line and not goes to the next line.
Following is the example, which helps us to understand the difference
Code:
Output:
As discussed above, we can see, the 3rd line contains print() method and 4th line contains println() method. So, after executing 3rd line,
cursor still on the same line in output and print the 4th line of code on same line. After executing the 4th line, cursor goes to the next line in the terminal. This is the small difference in these methods.
Thanks.
Comments
Post a Comment