answersLogoWhite

0


Best Answer

Do you mean how do you write a Java program to print out those numbers in ascending order? Because you have specified thosenumbers, I can only assume that the following will suffice:-

public int main( String[] args )

{

System.out.println( "0.235 4.62 7.25 7.89 23.5" );

}

If you want to know how to sort a general array into ascending order, try Google for sorting algorithms, such as "bubble sort", "insertion sort", "heap sort", "quick sort" etc.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

class Bubblesort{

public static void main(String a[]){

int i;

int array[] = {2345,12,1,111};

System.out.println("Values Before the sort:\n");

for(i = 0; i < array.length; i++)

System.out.print( array[i]+" ");

System.out.println();

bubble_srt(array, array.length);

System.out.print("Values after the sort:\n");

for(i = 0; i <array.length; i++)

System.out.print(array[i]+" ");

System.out.println();

System.out.println("PAUSE");

}

public static void bubble_srt( int a[], int n ){

int i, j,t=0;

for(i = 0; i < n; i++){

for(j = 1; j < (n-i); j++){

if(a[j-1] > a[j]){

t = a[j-1];

a[j-1]=a[j];

a[j]=t;

}

}

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

It should be fairly simple to program a bubble sort (though this is not very efficient for large arrays). If elements #0 and #1 of an array are out of order, exchange them. Then do the same with elements #1 and #2, etc., up to elements number (n-2) and (n-1). Then go back to the beginning, and repeat everything (n-1) times. (This will require two nested for loops.)

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

To sort any array of numbers, use the built in Arrays.sort() methods.

int[] array = new int[]{2345, 12, 1, 111};

Arrays.sort(array);

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

I suggest you do a bubble sort; that one is fairly easy to implement.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to write Short Java program to sort a sequence of numbers 2345 12 1 111 in ascending order?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What does ctagtcatga mean?

That appears to be a DNA sequence to something. That is too short of a sequence for anyone to tell you the species.


In MRI how do TR and T1 relate?

A long TR and short TE sequence is usually called Proton density -weightedA short TR and short TE sequence is usually called T1-weightedA long TR and long TE sequence is usually called T2-weighted


What does a short line in front of the word program mean---- program?

blank program


What are two features that make plasmid useful for transforming?

Simple and short DNA sequence and their inherent separation but later group into the genome sequence.


A change in the sequence of DNA that results in a protein that is too short?

Nonsense mutation


What are two features that make plasmids useful for transforming cells?

Simple and short DNA sequence and their inherent separation but later group into the genome sequence.


What is short program in figure skating?

Make a good reason why your leaving. Because you don't want to stay for a short program of figure skating.


What is program a long or short vowel?

long


What is a bullet train investment program?

Short term very high yield program


Why do o and b stars have a short life on the main sequence?

See related question


What do you call the short clip before an episode with the shows theme tune?

Title sequence


What does nos?

Nos is short for Numbers.