1.
The effective and most widely used technique to input data using java language is Scanner
Class.
2. Scanner Class allows users to input different types of data values.
3. Scanner Class is defined under
[Link] package.
4. Scanner Class needs JDK 1.5 or more, and BlueJ version 2.5 or more. Page |
5. Java output statements are 1
a. [Link]()
b. [Link]().
6. We must import [Link] package to avail facilities of the Scanner Class.
7. The syntax or process to import Scanner Class
import [Link];
8. We need to create an object of the Scanner Class to input any value using it.
9. The syntax to create a Scanner object
Scanner sc = new Scanner ([Link]); where sc is the object.
10. The new keyword is used for dynamic allocation of any object.
11. The parameter [Link] allows the constructor to receive data from the keyboard.
12. Define Dynamic Allocation
When the values are stored in dynamic memory through objects, it is referred to as dynamic
allocation.
13. Funtions to accept data using the Scanner Class
nextInt() - used to input an integer number and store it in an integer type variable.
nextFloat() - used to input floating value/fractional number and store it in a floating type
variable.
nextLong() - used to input a long value/larger than integer type and store it in a long type
variable.
nextDouble() - used to input a double value/larger than float type and store it in a double type
variable.
14.
Function Syntax
Scanner sc = new Scanner ([Link]);
nextInt() int i; int i = [Link]();
i = [Link]();
nextFloat() float f; float f = [Link]();
f = [Link]();
nextLong() long l; long l = [Link]();
l = [Link]();
nextDouble() double d; double d = [Link]();
d = [Link]();
15. Functions are also called Procedures in some computer languages.
16. Functions are also called Methods in most of the object-oriented languages.
17. Define Function
A function is a set of instructions grouped together to serve a specific operation in a computer
program so that users can develop program logic easily.
18.
Function Property Page |
[Link]() Used to return the maximum of two numbers
2
By default return integer type if both the arguments are integer else return
double type.
Syntax: <Return type> var_name = [Link](num_1,num_2);
Example:
int i = [Link](45,56); returns answer as 56
double n = [Link](55,78.5); returns answer as 78.5
double d = [Link](73.5,65.7); returns answer as 73.5
[Link]() Used to return the minimum of two numbers
By default return integer type if both the arguments are integer else return
double type.
Syntax: <Return type> var_name = [Link](num_1,num_2);
Example:
int i = [Link](45,56); returns answer as 45
double n = [Link](55,78.5); returns answer as 55.0
double d = [Link](73.5,65.7); returns answer as 65.7
[Link]() Used to return the power raised to the base.
By default return double type.
Syntax: <Return type> var_name = [Link](base,power);
Example:
double d = [Link](5,2); returns answer as 25.0
[Link]() Used to find the square root of a positive number.
Always return double type value.
Syntax: <Return type> var_name = [Link](num_1);
Example:
double d1 = [Link](144); returns answer as 12.0
double d2 = [Link](20.25); returns answer as 4.5