Page 279 - CA_Blue( J )_Class9
P. 279

Program 2      Write a program to swap two numbers.

                   1      class swap                                                //Class Name

                   2      {
                   3          public static void main()

                   4          {
                   5              int a,b,temp;                                     //Variable Declaration

                   6              a=5;
                   7              b=2;

                   8              System.out.println("Before Swapping : ");
                   9              System.out.println("a : "+ a + " b : " + b); //Displaying Original Value

                  10              temp = a ;
                  11              a = b;
                  12              b = temp;

                  13              System.out.println("After Swapping : ");

                  14              System.out.println("a : "+ a + " b : " + b); //Displaying Swapped Value
                  15           }                                                    //Close of main()
                  16      }                                                         //Close of class

                 You will get the following output:

                        Before Swapping :
                        a : 5 b : 2
                        After Swapping :
                        a : 2 b : 5

                                                        VARIABLE DESCRIPTION
                            NAME              DATATYPE                           DESCRIPTION
                                                                st
                       a                         int           1  Number
                       b                         int           2  Number
                                                                nd
                       temp                      int           Temporary variable to swap number

                 (ii)  Programs based on Input through parameters.
                                 Write a program to input the selling price and cost price and print the profit and profit
                  Program 3
                                 percentage.
                   1      class price                                    //Class name

                   2      {

                   3      public static void main(double sp, double cp){
                   4              double p, pp;                          //Variable
                   5              p=sp-cp;                               //Calculation of profit



                                                                                             Internal Assessment  277
   274   275   276   277   278   279   280   281   282   283   284