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

Program to read data from Keyboard using BufferedReader class in Java

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

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

import java.io.*;

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

 InputStreamReader isr = new InputStreamReader( System.in );
 BufferedReader br = new BufferedReader( isr );
 
 System.out.print(" Enter first Number : ");
 a = Integer.parseInt(br.readLine());
 System.out.print(" Enter second Number : ");
 b = Integer.parseInt(br.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.