Integer:

Function: Receives Integer input and stores in respective integer
variable.

Syntax:  

Integer.parseInt(<object name>.readLine() );

Example:   

int x= Integer.parseInt(bf.readLine());

Float:

Function:Receives Float input and stores in respective float variable.

Syntax:  

Float.parseFloat(<object name>.readLine() );

Example:   

float f= Float.parseFloat(bf.readLine());

Long:

Function: Receives Long input and stores in a respective long variable.

Syntax:  

Long.parseLong(<object name>.readLine() );

Example:   

long l= Long.parseLong(bf.readLine());

Double:

Function: Receives Double input and stores in respective double variable.

Syntax:

Double.parseDouble(<object name>.readLine() );

 Example:

double d= Double.parseDouble(bf.readLine());

String:

Function: Receives String input and stores in the respective String variable.

Syntax:  

String <variable name> = <object name>.readLine();

 Example:   

String s=bf.readLine();

Sample Program using Buffer Class:

import java.util.*;
class ScannerDemo
{
public static void main()
{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n Enter a Sentence: ");
String x=bf.readLine();
System.out.println("Entered Text is: "+x);
}
}

Output:

 

Report Error/ Suggestion

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019