Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Magazine get median in java

Have Programming Question? Ask it here!
 
 
 


Java Coder
get median in java
1 Answer(s)      2 years and 6 months ago
Posted in : Java Magazine


How to get the median value in Java from the given list.


Advertisement
View Answers

February 16, 2012 at 12:29 PM


import java.util.*;
class FindMedian {

public static int findMedian(int array[]) {
int length=array.length;
int[] sort = new int[length];
System.arraycopy(array, 0, sort, 0, sort.length);
Arrays.sort(sort);

if (length % 2 == 0) {
return (sort[(sort.length / 2) - 1] + sort[sort.length / 2]) / 2;
} else {
return sort[sort.length / 2];
}
}

public static void main(String[] args)
{
int min = 30;
int max = 50;
int[] ranNum = new int[5];
System.out.println("Enter Numbers:");
for ( int i = 0; i < ranNum.length; i++) {
ranNum[i] = (int)(Math.random() * (max - min + 1) ) + min;
System.out.println(ranNum[i]);
}
int median=Find.findMedian(ranNum);
System.out.println("Median= "+median);
}
}


Related Tutorials/Questions & Answers:
get median in java
get median in java  How to get the median value in Java from the given list.   import java.util.*; class FindMedian { public static int... median=Find.findMedian(ranNum); System.out.println("Median= "+median
Mean, Median and Mode - Java Beginners
Mean, Median and Mode  Write a java program that computes three measures of central tendency of a given set of students marks: mean, median, and mode...); System.out.println("Mean= "+mean); int median=Find.findMedian(ranNum
Advertisements
Java Find Median
Java Find Median In this tutorial, you will learn how to find the median of numbers. There is no built in method to find the median of a list of numbers in the Java framework. But you can create your own method when you need to find
get absolute time java
get absolute time java  How to get absolute time in java
java get file permission
java get file permission  How to check the get file permission in Java
How to get Java SDK
How to get Java SDK  Hi, I have purchased a new computer and installed windows 7. Now I have to get the Java SDK and install on my computer for developing and testing Java programs. So, can anyone tell me How to get Java SDK
Java get System Locale
Java get System Locale       In this section, you will learn how to obtain the locale. We are providing you an example which will obtain the locale of the system
how to get this xml syntx in java??????
how to get this xml syntx in java??????  how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
how to get this xml syntx in java??????
how to get this xml syntx in java??????   how to get this xml syntx in java?????? < comp xlink:type="new" xlink:actuate="onload"/>
How to get the current date in Java?
How to get the current date in Java?  Hi, I am new to Java... in Java? Thanks   Hi, Check the tutorial: Java program to get current date. Thanks   Hi, To get the current date and time in Java you can use
How to get enum value in Java
How to get enum value in Java  Hi all, i am looking for a solution to get an enum value from index in Java. Please suggest. Thanks
CORE JAVA get middle name
CORE JAVA get middle name  hello sir...how to get middle name using string tokenizer....??? eg..like name ANKIT it will select only K...!!!!   The given code accepts the name from the console and find the middle
Java get windows Username
Java get windows Username       In this section, you will learn how to obtain the window's username. We are providing you an example which will obtain the window's username
Java Get Example
Java Get Example      ... examples to get the things fast and practice these code at your end to learn java.... Java Get Examples.. Get host name in Java: This example is going
want to get job on java - Java Beginners
want to get job on java  want to get job on java what should be prepared.  To know java quickly. Just click the following links:http://www.roseindia.net/java/new-to-java.shtmlhttp://www.roseindia.net/java/java
Java Get Example
Java Get Example      ... examples to get the things fast and practice these code at your end to learn java.... Java Get Examples.. Get host name in Java: This example
get
get ( ) Method in PHP  what is get method in PHP   Please visit the following link: http://www.roseindia.net/php/php-Get-Post.shtml
How to get UTF-8 working in java webapps?
How to get UTF-8 working in java webapps?  How to get UTF-8 working in java webapps
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
In Java how to get size of class and object?
In Java how to get size of class and object?  In Java how to get size of class and object
Java Get Method
Java Get Method       In this example you will learn how to use the get method in Java. Java... to use get method in Java.  The example is going to show the date details
Java Get Memory
Java Get Memory       In this section of Java Example, you will see how to get the memory... can easily learn it. In this Java Get Memory Size example, we have created
Java get Next Day
Java get Next Day       In this section, you will study how to get the next day in java... DateFormatSymbols in order to get the names of the days of the week. The method getWeekdays
java how to get domain name from url
java how to get domain name from url  How to get the domain name from a url string? Example program in java for "how to get domain name from url" Thanks   Hi, You can use the following example code: URL linkURL
java code to get the internet explorer version
java code to get the internet explorer version  Hi, Could u plz help me in finding the internet explorer version using java code...i have the javascript but i want this in java code... Thanks, Pawan
How to get the unicode of japanese character input in java
How to get the unicode of japanese character input in java  Good Evening sir/madam; I am trying to create an application in java which needs to show the japanese character on frame and need to get the japanese string from
java get all ip addresses in a lan
java get all ip addresses in a lan  Anybody have any idea on using java or cpp on how to get the ip addresses of all the machines[win or linux] connected to a computer in a LAN?. If this is not possible is there any function
Get current working directory in Java
Get current working directory in Java In this section we will discuss about how to get the the current working directory in java. Current working... to get current directory in Java with Example public class
Java get byte array from file
Java get byte array from file  what is the code example in Java for getting byte array from file in memory. Thanks   This is very simple code in Java. Following tutorials will teach you how to achieve this. Java
Get computer name in java
Get computer name in java       We can get the computer name by the java code program... C:\javaexamples>java GetComputerName roseindia   Download
Java Get Month
Java Get Month       In the previous Java examples, we have discussed about date functions... the current month of the existing year. This Java get month example is simply
How to Get Started with Java?
A Java Beginners Tutorial - How to Get Started with Java? For a programmer Java offers some challenges that are uncommon with other environments and to get... system it is in use. So to get started with Java the first step would
how to get session object in simple java class??
how to get session object in simple java class??  i am fallowing...) GroupDetailsDao.java (it is also a simple java class which have the jdbc logic............................ is.................... now i need to get that session object (GroupPojo
Java get Free Memory
Java get Free Memory      ... to get the memory left of being allocated, the method getruntime() returns the runtime object associated with the Java application. freeMemory- This method returns
Java program to get the desktop Path
Java program to get the desktop Path       In this example program we have to get the desktop path of the system. In the java environment we can get the desktop path also
How to get the capacity of ByteBuffer in java.
How to get the capacity  of ByteBuffer in java.     ..., we will discuss how to get the capacity of buffer. The ByteBuffer class...;java ByteBufferCapacity  C:\Work\Bharat\load\ByteBuffercapicity
Get IP Address in Java
Get IP Address in Java In this example we will describe How to get ip address in java. An IP address is a numeric unique recognition number which is assigned to the devices participating in the network for communication
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML... only need to get
Java Get Host Name
Java Get Host Name       In this Example you will learn how to get host name in Java. Go through...; Java code to get host name import java.net.
how to get the next option - Java Beginners
how to get the next option  i was getting values from the database it was bulk so i want to keep the next option how to do in the jsp  Hi Friend, Please visit the following link: http://www.roseindia.net
get the value from another class - Java Beginners
get the value from another class  Hello to all, I have stupid question. I have main.java and ConfigXML.java(read my config xml file). Code from...().trim(); [/code] How I can get String alsl = ((Node)flnameTEXT.item(0
Java get default Locale
Java get default Locale     ..., or cultural region. We can get and set our default locale through the java programs...:\javaexamples>java GetDefaultLocale en_US   Download Source Code  
Java example to get Object class name at runtime
Java example to get Object class name at runtime       java get Object class name In java there is a way that makes us enabled to get the object class name at runtime. It can
Java get User Input
Java get User Input       In this section, you will learn how to get the user input from the command prompt. We are providing you a java application
Java Example program to get the current working directory
Java Example program to get the current working directory       This example java... object we can get two types of paths in java. These are as follows
How to get month name from date(like-25/06/2012) using java?
How to get month name from date(like-25/06/2012) using java?  How to get month name from date(like-25/06/2012) using java
how to get harddisk info using S.M.A.R.T using java
how to get harddisk info using S.M.A.R.T using java   how to get harddisk info using S.M.A.R.T using java
Java file get name
Java file get name In this section, you will learn how to get the name of the file. Description of code: You can see in the given example, we have created... get the name of any file. Output: File name is: out.txt
Java Get Last Line of File
Java Get Last Line of File     ... you in understanding Get Last Line of File in Java . For this we have a class name "Get Last Line of File". Inside the main method we create an instance
Java program to get current date
Java program to get current date now       In this example program we have to get... to get the calendar instance using the default specified time zone
Advertisements
 

 

 

DMCA.com