Page 149 - CA_Blue( J )_Class9
P. 149

Write a program to input the initial velocity, acceleration and time travelled. Calculate the
                  Program 2
                                 distance travelled by the body.
                   1      import java.util.*;

                   2      class distance_travelled
                   3          {

                   4              public static void main ()
                   5              {

                   6                  Scanner sc= new Scanner (System.in);
                   7                  double u,t,a,s;

                   8                  System.out.print("Enter initial velocity: ");
                   9                  u=sc.nextDouble();

                  10                  System.out.print("Enter the acceleration of the body: ");
                  11                  a=sc.nextDouble();
                  12                  System.out.print("Enter the time travelled: ");

                  13                  t=sc.nextDouble();

                  14                  s=(u*t) +1.0/2.0*a*Math.pow(t,2);
                  15                  System.out.println("The distance travelled: "+s+" km ");
                  16              }

                  17          }

                 You will get the following output:



















                  Program 3      Write a program to input the side of a equilateral triangle and calculate the area.

                   1      class equilateral
                   2          {

                   3              public static void main (double s)
                   4              {

                   5                  double a;
                   6                    a = Math.sqrt(3)/4.0*s*s;



                                                                                    Mathematical Library Methods   147
   144   145   146   147   148   149   150   151   152   153   154