Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Error!!, Java Beginners Arrayexamples MergeSort

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

;
 
Java Examples for Beginners
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

import java.io.*;
import java.util.*;

public class mergeSort{
public static void main(String a[])throws IOException{

BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the lenght of the array");
String len = bufferedreader.readLine();
int length = Integer.parseInt(len);
int[] arr = new int[length];

createArray(arr,length);
findPrimes(arr,length);
mergeSort1(arr,0,length);
}
public static void createArray(int arr[],int len)
{

int i;
Random random = new Random();
for(i=0;i<len;i++)
{
arr[i]=random.nextInt(101);
System.out.println(arr[i]+"");
}
}
public static void findPrimes(int arr[],int len)
{
int i;
for(i=0;i<len;i++)
{
if(isPrime(arr[i])==1)
System.out.println("Prime");
else
System.out.println("not prime");
}
}


public static int isPrime(int num)
{
double sqrt;
sqrt=Math.sqrt(num);
int i;
for(i=2;i<=(int)sqrt;i++)
if(num%i==0)
return 0;
return 1;
}

public static void mergeSort1(int array[],int lo, int n){
int low = lo;
int high = n;
if (low >= high) {
return;
}

int middle = (low + high) / 2;
mergeSort1(array, low, middle);
mergeSort1(array, middle + 1, high);
int end_low = middle;
int start_high = middle + 1;
while ((lo <= end_low) && (start_high <= high)) {
if (array[low] < array[start_high]) {
low++;
} else {
int Temp = array[start_high];
for (int k = start_high- 1; k >= low; k--) {
array[k+1] = array[k];
}
array[low] = Temp;
low++;
end_low++;
start_high++;
}
}
}
}

This code gives error out of bounds in mergeSort

Posted by AK on Friday, 01.15.10 @ 17:22pm | #94063

Ask programming questions?

 

 

Back to Tutorial
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.