Median Usage, Examples, Demos and Tutorials

Code Examples of Median

public static double getMedianTestScore(int testID)

throws SQLException

{

Logger

log = Logger.getLogger();

boolean

loggingEnabled = log.isLoggingEnabled();

Median

median = new Median();

ArrayList

arraylist = new ArrayList();

Connection

conn = getDefaultConnection();

try {

log.enableLogging( false );

PreparedStatement

ps = Utils.prepare

(

conn,

“select tk.score\n” +

“from TestTaking tk, LastTaking lt\n” +

“where tk.takingID = lt.takingID\n” +

“and tk.testID = ?\n”

);

ps.setInt( 1, testID );

ResultSet

rs = ps.executeQuery();

while( rs.next() )

{

arraylist.add(new Double(rs.getDouble(1)));

}

Utils.close(rs);

Utils.close(ps);

}

finally

{

log.enableLogging( loggingEnabled );

}

int

count = arraylist.size();

double

values[] = new double[ count ];

for ( int i = 0; i < count; i++) { values[ i ] = ((Double)arraylist.get(i)).doubleValue(); } return median.evaluate( values ); } /** *

* Format a double as a percentage, suitable for printing.

Copyright © 2011 www.androidadb.com. All rights reserved. All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc. Contact . See also:

|

|

|