This program tell you how to take user input using java programing.
you only have to do add two line in program one is[InputStreamReader ir=new InputStreamReader(System.in);] which tell the java compiler that user is providing input from keybord, and 2nd line is [BufferedReader br=new BufferedReader(ir);]
hear java program take the input of user as buffer or in other word take in buffer memory.
In both line 6 and 7 we make object of InputStreamReader and BufferedReader method which are pre defined in java compiler.
We have to make object of each method to instantiate in a program, or in other word
if you want to use method in java user define or pre define you must have to make object of that methat.
source code
- import java.io.*;
- class user_input_two_no_for_sum
- {
- public static void main(String[] args)throws IOException
- {
- InputStreamReader ir=new InputStreamReader(System.in);
- BufferedReader br=new BufferedReader(ir);
- int no1,no2,sum;
- System.out.println("Enter no1=");
- no1=Integer.parseInt(br.readLine());
- System.out.println("Enter no2=");
- no2=Integer.parseInt(br.readLine());
- sum=no1+no2;
- System.out.println("Total="+sum);
- }
- }
No comments:
Post a Comment