Instead Of HelloWorld                      Peter Komisar



 

class AsTheCrowFlies{                                                            // In Java everything is defined inside a class
   public static void main(String[] args){                                     // Every Java app starts with a main function

   int horizontal;
   int vertical;
   int flaps;
   double slope;

 if(args.length==0)                                                        // if there are no arguments at the command line
    System.out.println("Enter the vertical and horizontal " +                         // provide some instruction
    "distances \n of the crow's flight in wing flaps. ");

   else if(args.length>0){
      vertical=Integer.parseInt(args[0]);         // arguments taken from the command line are String type and
      horizontal=Integer.parseInt(args[1]);              //may need to be converted to the other types.  Here the
                                                                                               //  Integer class provides the method parseInt( ) to do this

      flaps=(int)oldCrowFormula(vertical, horizontal);         // the method returning the hypotenuse,( not to
                                           // be confused with hippopotamus), is marked static thereby becoming a  'class'
                                                                 //   or static method which does not need to be called off of a class instance
     System.out.println("As the crow flies, the crow flies "              // the standard way to print to console
      + flaps + " wing flaps " );
     }
  }
                                                                                      // this method takes two int type parameters and returns a double
static double oldCrowFormula (int x, int y){
     double crowflies= Math.sqrt ( (x*x) + (y*y) );
     return crowflies;
     }
}