Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

print method in java

#Here are few methods to print data.
  
1) System.out.println(); --> move the cursor on new line
2) System.out.print();   --> on same line
3) System.out.printf();  --> on same line

java providing build-in class called System, and System class is having
build-in object called out, this object is attached to the monitor or console,
means a static object.
  
and the out object having the methods called println, print, and printf, etc.
print method takes parameters or values, means parameter in different type.
print method support all data type like --> int, float, char, String, double,
long, etc.

NOTE : if method can have same name but different in parameters called 
overloaded method, so print method is also a overloaded method but passing 
different in parameters.

###############################################
IMPORTANT NOTE : 

suppose x and y are two variables and it contains int type value as 5 and 6.
Then how the print method will works ?
 
.........................................
System.out.println("Hello " + x + y);

First string is concatenate with x and then concatenate with y
the output we get --> Hello 56.
.......................................
  
In Other way ----------
  
.......................................
System.out.println(x + y + " Hello");

First x and y will add and then concatenate with string.
the output we get --> 11 Hello

......................................
  
#########################################

if to achieve the first way to add x and y use parentheses () arount x and y
like  (x + y), now it add and then concatenate

System.out.println("Hello " + (x + y));

output --> Hello 11



Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #print #method #java
ADD COMMENT
Topic
Name
4+4 =