Java println and print methods
Java println and print methods
The java print method :
Like other programming languages Java has a print function that is uesd to output message.
The method used is :
System.out.println("Message to print")
Description :
-System is the predefined class that provides access to the System.
Note that in Java all classes name start with capital letter.
-out is the static method
-println is the method of the printstream class.
Example :
public static void main(String args[])
{
int a;
int b;
int sum=0;
sum=a+b;
System.out.println("This is print method")
}
The output to this code is :
This is print method.
Note :
System.out.printl() can also be used as print method in java.
The functionality of the both method is same that is to print the message or result.
But there is a slight difference between these two functions. The difference is discussed below.
Difference b/w print and println method :
print() : This method displays the result and then place the cursor in the same line.
println() : This method displays the result and throws the cursor to the next line.
Note :
print() and println() are belongs to the PRINTSTREAM class in Java.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment