The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

May loose your degree!!!

Posted by Kishori Sharan on January 18, 2001 at 9:28 AM

1) Get the sum of all values in h[]
int s = 0 ;

for ( int i = 0 ; i < h.length ; i++ ) {
s = s + h[i] ;
}

2) Calculate degree values
for ( int i = 0 ; i < h.length ; i++ ) {
dg[i] = ( int ) ( h[i] * 360 ) / s ;
}
Please note that you will loose fractional part of degree because dg[] is int and we are casting the degree value to int.



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us