You are here: Home / Topics / Program to read data using Console class and display data in Java

Program to read data using Console class and display data in Java

Filed under: Java on 2024-03-01 06:51:54

// Program to read data using Console class and display data.

import java.io.*;

class Swap5
{
public static void main( String args[ ] ) throws IOException
{
 int  a=0, b=0, t;
 Console cn = System.console();
 
 a = Integer.parseInt( cn.readLine( " Enter first Number : " ));
 b = Integer.parseInt( cn.readLine( " Enter second Number : " ));

 System.out.println( " Before Swapping : " + a + "   " + b );
 
 a = a + b;
 b = a - b;
 a = a - b;
 
 System.out.println( " After Swapping : " + 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.