Page 83 - CA_Blue( J )_Class10
P. 83
5.3 USING PARAMETERS
We can take values using parameters passed to methods. This method allows you to take values using command line
arguments or during method call at the time of execution of a program.
i. Using Command-Line Arguments: These arguments allow us to take values during the execution of a program.
These values are taken through the String[] args array passed in the main( ) method. Command-line arguments are
mainly used to input String values. We can take any type of value using command-line arguments. However, we
need to convert the input value to the respective type. For example:
Program 3 To input the principal amount, rate of interest and time, and print the Simple Interest.
1 class command_line_argument
2 {
3 public static void main(String args[])
4 {
5 double p,r,t,si=0.0;
6 p=Double.valueOf(args[0]);
7 r=Double.valueOf(args[1]);
8 t=Double.valueOf(args[2]);
9 si=(p*r*t)/100.0;
10 System.out.println("Simple Interest : "+ si);
11 }
12 }
You will get the following output:
ii. During Method Call: Through this procedure, we can take direct values in the variables using parameters at the time
of execution. For example:
Program 4 To input three numbers and print the sum and average in tabular format.
1 class method_call
2 {
3 void sum_average(double a,double b, double c)
4 {
5 double sum,avg;
6 sum=a+b+c;
81
Input in Java 81

