mathajax

Java Stream Input using BifferedReader

Add two numbers
The java code add two numbers which are given as input to the code. The buffered reader object instance initialized to read the inputs from keyword.



package cljavabasics;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class StreamInput {

 public static void main(String[] args) throws IOException 
       {
  
        
 InputStreamReader dis =new InputStreamReader ( System.in );
 BufferedReader br =new BufferedReader(dis);
  
 System.out.println("Sum of Two Numbersn");

 System.out.println("Enter first value");    
 String  arg1 =br.readLine();
 int a = Integer.parseInt(arg1);     

 System.out.println("Enter second value");
 String  arg2 =br.readLine();
 int b = Integer.parseInt(arg2);     

 int c= a+b;   
 System.out.println("ans   : " + c );
  
  
 }

}


Output
Sum of Two Numbers

Enter first value
30
Enter second value
40
ans   : 70

Comments

Popular posts from this blog

Matrix Forward and Back Substitution

Chebyshev distance between two points

Solve System of Linear Equations by LU Decompose

Complex number Multiplication and Division

Matrix Determinant, Matrix Adjoint and Matrix Inverse