BLOG

JAVA

How to get Input from the user in Java

Hello Friends !!
Here you can see how to take input from the user :
-> First of all you have to call input/output Package named "java.io." .
-> Here is the Program :


import java.io.
;
class input
{
public static void main(String args[]) throws Exception
{
int m1,m2,total;//Local Variables
DataInputStream ds;


m1=00;//if user not enter any value then it will assign 0.
m2=00;
ds = new DataInputStream(System.in);//creating object of inputstream



System.out.println("Enter the m1:");
m1=Integer.parseInt(ds.readLine());//taking input from user
System.out.println("Enter the m2:");
m2=Integer.parseInt(ds.readLine());

total=m1+m2;
System.out.println("The addition is:"+total);

}
}



-> Save this Program as input.java .
-> Thank you .

Back to posts
Comments:
[2011-08-24 02:48] DISHANT:

thanks bharat

[2011-08-22 22:27] bharat:

very good

[2011-08-21 04:26] Dishant:

Thanks kushal. Pan tara jevu hu na banavi saku.

[2011-08-21 04:17] Kushal:

Nice work keep it up...!!


Post a comment


>Back

Lamborghini Huracán LP 610-4 t