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

Recent Posts

Build Simple Water System Calculator in Java Using Swing

If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…

13 hours ago

GitHub Copilot vs Microsoft Copilot Best AI Tool to Use in 2025

GitHub is a powerful tool used by teams and developers around the globe. This guide is…

5 days ago

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

1 week ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

2 weeks ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

2 weeks ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

2 weeks ago