Sorting an array using a void method?
-
I need help with sorting the integers with the smallest value first. Please help i. Creates an integer array with 100 random integers. ii. Sorts the array in numeric order with the smallest value first. iii. Displays the results with 10 numbers per line. public class SortIntArray { public static int[] createIntArray() { int[] list = new int[100]; for (int i = 0; i < list.length; i++) list[i] = (int) (Math.random()* 100); return list; //1. declare, create an array of 100 whole numbers; //2. initialize array elements to be 100 random numbers // within range of 0 - 99 // Math.random //3. return the array } public static void sortIntArray(int[] list) { // use sort() in Arrays class to sort integers in // array numbers } public static void printIntArray(int[] list) { //print array numbers with 10 numbers per line for (int i = 0; i < list.length; i++) { if ((i + 1) % 10 == 0) System.out.println(list[i]); else System.out.print(list[i]+ " "); } } }
-
Answer:
i am out of programming however the basis loginc is int:temp1 for (j=0:j<10,j++) { for (k=0;k<j-1;k++)] if (list[j]<list[k]) { temp1=list[j] list[j]=list[k] list[k]=temp1 } } make a function out of it.
chr017 at Yahoo! Answers Visit the source
Related Q & A:
- How To Connect Two Different Network Segments Using A Switch And A Router?Best solution by Super User
- What is the difference between a static method and class method in Python?Best solution by pythoncentral.io
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- Is there a certain method used to analysis?Best solution by www2.uiah.fi
- How to connect a psp go to a PS3 controller using a computer?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.