1: Program using Scanner| Data input Scream|Buffered Reader

1: Program using Scanner| Data input Scream|Buffered Reader

Also, you can use the Java compiler to compile a program.

Buffered Reader class.

SOURCE CODE:

import java.io.*;
class Rbuf
{
    public static void main(String args[]) throws IOException
 {
    int rollno;
    String name;
    float salary;
    
    BufferedReader s=new BufferedReader(new 
     InputStreamReader(System.in)); 
    //Create  object  
    
    System.out.println("Enter the Roll no:");
    rollno=Integer.parseInt(s.readLine()); //Input

    System.out.println("Enter the Name:");
    name=s.readLine(); //Input

    System.out.println("Enter the Salary:");
    salary=Float.parseFloat(s.readLine()); //Input

    System.out.println("Roll no:"+rollno);
    System.out.println("Name:"+name);
    System.out.println("Salary:"+salary);
 } //End of main
} //End of class

OUTPUT:


C:\A>javac Rbuf.java

C:\A>java Rbuf

Enter the Roll no:

59

Enter the Name:

SAM

Enter the Salary:

500

Roll no:59

Name:SAM

Salary:500.0



Data input Scream Class.

SOURCE CODE:

import java.io.*;
class Rdiss
{
    public static void main(String args[]) throws IOException
 {
    int rollno;
    String name;
    float salary;
    DataInputStream s=new DataInputStream(System.in); //Create 
    object
    
    System.out.println("Enter the Roll no:");
    rollno=Integer.parseInt(s.readLine()); //Input

    System.out.println("Enter the Name:");
    name=s.readLine(); //Input

    System.out.println("Enter the Salary:");
    salary=Float.parseFloat(s.readLine()); //Input

    System.out.println("Roll no:"+rollno);
    System.out.println("Name:"+name);
    System.out.println("Salary:"+salary);
 } //End of main
} //End of class

OUTPUT:

C:\A>javac Rdiss.java

C:\A>java Rdiss

Enter the Roll no:

01

Enter the Name:

SAM

Enter the Salary:500

Roll no:1

Name:SAM

Salary:500.0

Scanner class.

Source Code.

import java.util.*;
class Rscanner
{
    public static void main(String args[]) 
    
 {
   int rollno;
   String name;
   float salary;
   Scanner s=new Scanner(System.in); //Create object
    
    System.out.println("Enter the Roll no:");
    rollno=s.nextInt(); //Input

    System.out.println("Enter the Name:");
     name=s.next(); //Input

    System.out.println("Enter the Salary:");
    salary=s.nextFloat(); //Input

    System.out.println("Roll no:"+rollno);
    System.out.println("Name:"+name);
    System.out.println("Salary:"+salary);
 } //END OF MAIN
} // END OF CLASS

OUTPUT.


C:\A>javac Rscanner.java

C:\A>java Rscanner

Enter the Roll no:

01

Enter the Name:

SAM

Enter the Salary:

500

Roll no:1

Name:SAM

Salary:500.0

Also View: – Write a program to create a registration form using AWT.

Also View- Write a java program to create a window using swing.

1 thought on “1: Program using Scanner| Data input Scream|Buffered Reader

Leave a Reply