Page 66 - iprime_V2.2_class8
P. 66

TAKING VALUES AS ARGUMENTS

                  Until now, we have initialised the variables before using them. Java also allows us to take values
                  of variables from the user at runtime. We can do this by passing arguments into the main()
                  method.

                  We can accept a single value as well as multiple values by separating them with a comma in the
                  following way:
                  public class Arguments

                  {
                       public static void main(int roll_no,
                        String name)
                      {

                           System.out.println("Roll number is: " + roll_no);
                           System.out.println("Name is: " + name);

                      }
                  }


                  When we execute the preceding program in BlueJ,
                  the Method Call dialog box appears, asking us to
                  enter the required arguments as shown.






                                                                                        Method Call Dialog Box

                                                                 After  entering  the  value of the arguments,  click
                                                                 on the OK button. The output will appear in the
                                                                 terminal window as shown.






                                    Output

                     Reb             t


                          A computer program can be defined as a collection of instructions to perform a specific
                         task.
                          The process of writing a program is called program coding, or programming.

                          There are mainly two types of programming languages: procedural and object-oriented.
                          Java is an object-oriented and high-level programming language.

                          Java follows the Write Once Run Anywhere (WORA) principle.



                  64     iPRIME (Ver. 2.2)–VIII
   61   62   63   64   65   66   67   68   69   70   71