In Java to accept input from user there are many libraries like Scanner,Textfields etc...
To use Scanner we have to import the Scanner into our program so we can do this by using
following statement
import java.util.Scanner;
now we can create object of Scanner type by using following statements
Scanner input=new Scanner(System.in);
thus we can accept data from user
Program :
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String []args)
{
float a;
int b;
Scanner input=new Scanner(System.in);
System.out.println("Enter Two Values");
a=input.nextFloat(); //for accepting float data
b=input.nextInt(); //for accepting int data
float c=a+b;
System.out.println("Sum is :"+c );
}
}
Output :
To use Scanner we have to import the Scanner into our program so we can do this by using
following statement
import java.util.Scanner;
now we can create object of Scanner type by using following statements
Scanner input=new Scanner(System.in);
thus we can accept data from user
Program :
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String []args)
{
float a;
int b;
Scanner input=new Scanner(System.in);
System.out.println("Enter Two Values");
a=input.nextFloat(); //for accepting float data
b=input.nextInt(); //for accepting int data
float c=a+b;
System.out.println("Sum is :"+c );
}
}
Output :