Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2008, 09:39 PM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Computing the area of a triangle using Heron's Formula
This Java program computes the area of a triangle using Heron's Formula.

Code:
public class Heron {
  public static void main(String[] args) {
    // Sides for triangle in float
    float af, bf, cf;
    float sf, areaf;

    // Ditto in double
    double ad, bd, cd;
    double sd, aread;

    // Area of triangle in float
    af = 12345679.0f;
    bf = 12345678.0f;
    cf = 1.01233995f;

    sf = (af+bf+cf)/2.0f;
    areaf = (float)Math.sqrt(sf * (sf - af) * (sf - bf) * (sf - cf));
    System.out.println("Single precision: " + areaf);

    // Area of triangle in double
    ad = 12345679.0;
    bd = 12345678.0;
    cd = 1.01233995;

    sd = (ad+bd+cd)/2.0d;
    aread =        Math.sqrt(sd * (sd - ad) * (sd - bd) * (sd - cd));
    System.out.println("Double precision: " + aread);
  }
}
__________________
"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
change the square to triangle java anotsu New To Java 3 07-09-2009 12:17 PM
Triangle jkswebsite New To Java 8 01-10-2009 03:08 PM
Making triangle banie New To Java 4 02-02-2008 12:23 PM
What is the formula? yuchuang New To Java 3 04-30-2007 11:00 PM


All times are GMT +2. The time now is 11:34 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org