MSN Messengar: Quickening@live.com

Sunday, March 16, 2008

Simple Java Programming: Sorting An Array

This is the Java program, MyList, an interactive system which allows users to input the size of an array and the desired elements for the array. The array is then sorted using the java.util package.

It contains the following functions:
- showAscending: using for-loop, it shows the elements in an ascending order
- showDescending: using for-loop, it prints the array in reverse, from last to first
- showMax: it selects the last element in the sorted array
- showMin: it selects the first element in the sorted array
- showPrime: calculates each element in the array using a Boolean expression by selecting an odd number value and divides it within a while-loop. Shows only prime numbers


Flowchart


---START---

public class MyList{

//Main insertion sorting
static void insert(int[] array, int free_pos, int val) {
int pos = 0;
for(; pos < free_pos; ++pos) {
if(array[pos] > val) {
break;
}
}

for(int i = free_pos; i > pos; --i) {
array[i] = array[i - 1];
}

array[pos] = val;
}
//Array command for insertion sort
static void sort(int[] array) {
for(int i = 1; i < array.length; ++i) {
insert(array, i, array[i]);
}
}

//Main Command
public static void main(String args[]){

int x=Integer.parseInt(args[0]);
int[] y;
y = new int[x];

for(int i = 0; i < x.length; ++i) {
int y=Integer.parseInt(args[i]);
}

System.out.println("The ascending is: " +x);

System.out.println("The descending is: ");

System.out.println("The max number is: ");

System.out.println("The min number is: ");

System.out.println("The prime numbers are: ");

}
}

---END---


Output Screenshot *click to see*


References:
J. R. Hubbard, Ph.D, Schaum’s Outlines: Programming with Java, Second Edition, McGraw-Hill, USA, 2004.

5 Minds bloomed here too...:

Anonymous said...

I'm the sort of hombre who enjoys to try fresh things. Currently I'm making my personalized photovoltaic panels. I'm managing it all by myself without the assistance of my men. I am using the internet as the only path to acheive that. I stumbled upon a truly brilliant website that explains how to create photovoltaic panels and so on. The web site explains all the steps required to solar panel construction.

I'm not really sure about how precise the info given there iz. If some guys over here who had experience with these works can have a look and give your feedback in the page it would be awesome and I'd really value it, cauze I truly like solar panel construction.

Tnx for reading this. You guys are great.

Anonymous said...

Generally I do not post on blogs, but I would love to mention that this post extremely forced me to try and do therefore! really nice post. thanks, here's a similar subject you'll like [url=http://www.blogabond.com/Comments/CommentPreview.aspx?CommentID=160156]Old Clocks[/url]

Anonymous said...

I am truly happy to read this webpage posts which carries plenty of valuable data, thanks for
providing these data.

My weblog ... microsoft registry cleaner
Also see my webpage - best registry cleaner

Anonymous said...

Attractive component of content. I just stumbled upon your site and in accession
capital to say that I get in fact loved account your blog posts.
Any way I will be subscribing on your augment and even I success
you get right of entry to persistently rapidly.


Feel free to surf to my web blog: SEO virtual assistants

Anonymous said...

After looking into a few of the articles on your site,
I honestly like your way of writing a blog.

I added it to my bookmark webpage list and will be checking back soon.

Please check out my web site too and let me know what you think.


Feel free to surf to my web-site what is a graduate certificate

More Weeds...

Add to Technorati Favorites Blogroll.net Bloggapedia, Blog Directory - Find It! Blog Flux Directory blog directory Blog Directory & Search engine Show off your blog Blogarama - The Blog Directory BlogGod Webloogle Blog Directory Blogging Fusion Blog Directory All Malaysian Bloggers Project