Page 106 - CA_Blue( J )_Class10
P. 106

21 st
               Some More Programs                                                  Century   #Coding & Computational Thinking
                                                                                    Skills
                             To input x and y values of two points A and B. Calculate the distance between the two points using
                Program 1
                             the following formula:
                             Distance =  (x2 - x1)  + (y2 - y1) 2
                                                2
                             The two points are A (x1, y1) and B (x2, y2).
                 1  import java.util.*;

                 2  class distance
                 3      {

                 4          public static void main ()
                 5          {

                 6              Scanner sc= new Scanner (System.in);
                 7              double x1, x2, y1, y2, dis;

                 8              System.out.println("Enter x and y axis of point A: ");
                 9              x1=sc.nextDouble();

                10              y1=sc.nextDouble();
                11              System.out.println("Enter x and y axis of point B: ");

                12              x2=sc.nextDouble();
                13              y2=sc.nextDouble();

                14              dis=Math.sqrt(Math.pow((x2-x1),2) +Math.pow((y2-y1),2));
                15              System.out.println("The distance between A and B is: "+dis);

                16          }
                17      }

              You will get the following output:














                             To input the initial velocity, acceleration and time travelled. Calculate the distance travelled by the
                Program 2
                             body.

                 1  import java.util.*;
                 2  class distance_travelled

                 3      {
                 4          public static void main ()



                104104  Touchpad Computer Applications-X
   101   102   103   104   105   106   107   108   109   110   111