Page 243 - CA_Blue( J )_Class10
P. 243

Write a program to find the difference of the two Algebric Expressions.
                  Program 5      f1 = ax +3x+5
                                       2
                                 f2 = x +2x+4
                                      2
                                 The program should be done using functions.
                   1  import java.util.*;

                   2  class function_algebra
                   3  {

                   4      static int expression1(int a,int x)
                   5      {

                   6          int r1 = (a*x*x)+ (3*x) + 5;

                   7          return r1;
                   8      }
                   9      static int expression2(int x)

                  10      {
                  11          int r2 = (x*x)+ (2 * x) + 4;

                  12          return r2;
                  13      }

                  14      public static void main()
                  15      {

                  16          Scanner sc= new Scanner(System.in);
                  17          int a,x1,x2,d;

                  18          System.out.println("Take a and x for expression 1:");
                  19          a=sc.nextInt();

                  20          x1=sc.nextInt();
                  21          System.out.println("Take x for expression 2:");

                  22          x2=sc.nextInt();
                  23          d=expression1(a,x1)-expression2(x2);

                  24          System.out.println("Result : "+d);
                  25      }

                  26  }
















                                                                                                                       241
                                                                                                 User-defined Methods   241
   238   239   240   241   242   243   244   245   246   247   248