Read my previous tutorial if you don't know how to compile and run java programs.
- Remember Java is Case Sensitive language i.e. You must take care of Capital and small letters.
- Like in turbo C, C++ we use "void main" or "int main", similarly in java we will use
public static void main(String args[])throws IOException
{
}
wherepublic : It is a keyword and it means the main method is publicly available.
static : It is a keyword and any other class can call this main method without any restriction.
void : It means main() will not return any value.
String args[] : args is the parameter of type String.
throws IOException : To prevent error while compiling.
SYNTAX :
DataInputStream object_name = new DataInputStream(System.in) ;
Here We have created a new object named "object_name" using the "new" keyword of class "DataInputStream". We can now use this "object name" in our program to take input.
Examples :
Copy each codes and compile and execute it.
------------------------------------------------------------------------------------------------------------
to get int type input -->
------------------------------------------------------------------------------------------------------------
/*Here we have created object named "s" to take input. Similarly we will take input of different data types using this object named "s" .*/
/*Note this a comment in Java*/
/* Note the symbols i have used for comments */
------------------------------------------------------------------------------------------------------------
to get char type input -->
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
to get float type input -->>
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
to get String type input -->> (note String S is capital)
------------------------------------------------------------------------------------------------------------
You have to remember these 4 methods.
And for output we use System.out.print("text to print on screen");
We will use this DataInputStream class in next programs. Remember these programs.
Follow the video tutorial for better understanding...
0 comments:
Post a Comment