skip to main |
skip to sidebar
SITE MADE BY KUSHAL SHAH
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. and System.in is a interface.
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 .
0 comments:
Post a Comment