You are here: Home / Topics / Program to read data from Keyboard using DataInputStream class in Java

Program to read data from Keyboard using DataInputStream class in Java

Filed under: Java on 2024-03-01 06:50:50

// Program to read data from Keyboard using DataInputStream class.

import java.io.*;

class  Swap3
{
public static void main( String args[ ] ) throws IOException
{
 int  a=0, b=0, t;

 DataInputStream dis = new DataInputStream(System.in );
 
 System.out.print(" Enter first Number : ");
 a = Integer.parseInt(dis.readLine());
 System.out.print(" Enter second Number : ");
 b = Integer.parseInt(dis.readLine());

 System.out.print( "\n Before Swapping : " );
 System.out.print( a + "   " + b );

 a = a + b;
 b = a - b;
 a = a - b;
 
 System.out.print( "\n After Swapping  : " );
 System.out.print( a + "   " + b );
}
}


Output:

Enter first Number : 100
Enter second Number : 200

Before Swapping : 100  200
After Swapping  : 200  100

About Author:
G
Geetam     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.