scanner in java scanner class in java scanner in java example using scanner in java scanner example in java
use of scanner in java scanner method in java scanner class in java scanner class in java with example
scanner in java example read in file scanner in java api scanner class in java api
Scanner Or
java.util.Scanner :
Scanner is one
of the predefined class present in java .util.* package. The basic aim of
Scanner class is to read the data from keyboard dynamically.
Profile Of Scanner
:
1) Scanner(InputStream) :
This Scanner constructor
in which Inputstream is one of the predefined class whose object called in
created as static data member in System class.
System.in is always gives control
to keyboard.
Ex : Scanner s=new Scanner(System.in);
Instance Methods :
2) Public Xxx nextXxx() :
This method is used for
reading fundamental values from keyboard. And Xxx represents any fundamental
data type.
For Example :
Public int nextInt()
Public float nextFloat()………etc……
3) Public String nextLine() :
This method is used for
reading any type of value from keyboard in the form of String type
The Following Program the
concept of Scanner Class :
import java.util.*;
class dataread
{
Public static void main(String
args[])
{
Scanner s=new Scanner(System.in);
System.out.println(“Enter the
first number”);
String s1=s.nextLine();
System.out.println(“Enter the
Second number”);
String s2=s.nextLine();
int
result=Integer.parseInt(s1)+Integer.parseInt(s2);
System.out.println(“Total
result is” +result);
}
}
Data
Extraction Interfaces are as follows :
1- D and 2-D Collection Frame work classes are
No comments:
Post a Comment