Java

DataInputStream Class

The Class DataInputStream is baselly handle a primitive type data types

 

Example 1

write a programme to input your Firstname,lastname input them.

import java.io.*;

public class DataInputstream {

   
    public static void main(String[] args) 
    {

            DataInputStream dis = new DataInputStream(System.in);
            String fname,lname;
            
            fname = "";
            lname = "";

           
        try 
          {
            System.out.print("Enter Your FirstName");
            fname = dis.readLine();
            System.out.print("Enter Your LastName");
            lname = dis.readLine();
             
            System.out.println("FirstName is "+ fname);
            System.out.println("LastName is "+ lname);
             
            
        } 
         catch (IOException ex) 
        {
           ex.printStackTrace();
        }
  
    }
    
}

Example 2

write a programme to input your num1,num2 and calculate the total.

import java.io.*;


public class DataInputstream {

   
    public static void main(String[] args) 
    {
            DataInputStream dis = new DataInputStream(System.in);
            int  num1,num2,tot;
        try 
         {
             System.out.print("Enter Your Num1");
             num1 = Integer.parseInt(dis.readLine());
             System.out.print("Enter Your Num2");
             num2 = Integer.parseInt(dis.readLine());
             tot = num1 + num2;
             System.out.println("Total  is "+ tot);
             
        } 
        catch (IOException ex)
        {
           ex.printStackTrace();
        }
    }
    
}

I have attached the video tutorial below it will help you  to do this  step by step.

 

admin

Share
Published by
admin

Recent Posts

Conditional Statements in Python

Conditional statements in Python allow us to control the flow of execution based on conditions.…

1 week ago

Java Beans

A Java Bean is a reusable software component that follows a specific set of conventions.…

2 weeks ago

Java String Methods

Java provides a rich set of built-in methods for handling String operations efficiently. Since strings…

2 weeks ago

Java Developer Jobs

Java remains one of the most in-demand programming languages worldwide, powering everything from enterprise applications…

2 weeks ago

Converting Integer to String in Java

Java provides multiple ways to convert an integer (int) to a string (String). Whether you're…

2 weeks ago

JSP to JSP Communication: A Complete Guide to Dynamic Java Web Development

Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…

3 weeks ago