Example using DataInputStream

Here we explain the example of a java program using DataInputStream. In this example we take two value a and b from user and calculate the sum of these two number using DataInputStream.
We can see below the java program.


/*Example using DataInputStream.*/
     
package com.javaforecast4u.io;

      import java.io.DataInputStream;

      public class InputOutput
      {
            public static void main(String[] as)
            {
                  try
                  {
                        DataInputStream dis = new DataInputStream(System.in);
                        System.out.println("Enter First Number");
                        int a =Integer.parseInt(dis.readLine());
                        System.out.println("Enter Second Number");
                        int b = Integer.parseInt(dis.readLine());
                        int sum = a+b;
                        System.out.println("Sum is "+sum);
                       
                  }
                  catch (Exception e)
                  {
                        e.printStackTrace();
                  }
            }
       }

Output:

Enter First Number
2
Enter Second Number
4
Sum is 6

0 comments :

Post a Comment