Friday, December 23, 2011

Program to calcute speed


import java.util.*;

public class Ch2Q20
{
 public static void main(String[] args)
  {Scanner kbd = new Scanner(System.in);
  final double g = 9.81;
  System.out.print("Enter initial distance: ");
  double s0 = kbd.nextDouble();
  System.out.print("Enter initial velocity: ");
  double v0 = kbd.nextDouble();
     double s = s0+v0+g/2;
     System.out.printf("%d\t\t%6.2f\n", 1, s);
     for(int t=5; t<=100; t+=5)
        {s = s0+v0*t+g*t*t/2;
        System.out.printf("%d\t\t%6.2f\n", t, s);
        }
    }
}

No comments:

Post a Comment