Input and Output Statements: java.lang
package consists a class called ‘System’ which contains console I/O methods. If we want to take the information from the
keyboard and display the information on the screen, Java uses Stream
objects. The system provides three basic
streams. Those are
a)
System.in
b)
System.out
c)
System.err
System.in refers to the standard
input stream, System.out refers to the standard output stream and System.err
refers to the standard error stream.
System.out class consists of two
methods to print the strings and values on the screen. They are 1. print( ) 2. println( ).
1. print( ): Syntax: System.out.print(list);
This statement prints the values of the variable name
specified in the list of output unit.
Example: System.out.print(“hai”);
System.out.print(“java”);
O/P: haijava
2. println( ):
Syntax: System.out.println(list);
This
statement prints the values of the variable name in the list, the cursor is
advanced by one line and the next statement is print in the next line.
Example: System.out.print(“hai”);
System.out.print(“java”);
O/P: hai
java
Note: Java has a version
of the ‘+’ operator for string concatenation that enables a string and a value
of another datatype.
Example: sum = 50
“sum
is” + sum
Here,
sum is automatically converted to a string and concatenated with the “sum is”
which results in the string sum is 50
Example: “y#2=”+7
O/P: y#2=7
Command Line Arguments: Java has the
facility of command line arguments. Java
main method consists array of string objects.
When we run the program, the array will fill with the values of any
arguments it was given in the command line.
No comments:
Post a Comment