Vote count:
0
public class lab
{
public static void main(String args[] )
{
///Code enclosed i cannot change///////////////////
int ar[] = {7,5,2,8,4,9,6};
int sorted[] = new int[ar.length];
int smallest = 100000;
int indexsmallest = 0;
///////////////////////////////////`
for (int i = 0;i<ar.length;i++)
{
// I am missing this code this is supposed to loop through array n number of
//times and store the lowest element and put in second array.
for (int j = 0; j<ar.length; j++)
{
if(ar[j] < smallest)
{
smallest = ar[j];
indexsmallest = j;
}
}
}
sorted[0] = smallest;
ar[indexsmallest]=smallest;
smallest=smallest;
//Code below I cannot Change
for(int i = 0; i <sorted.length;i++)
{
System.out.println("sorted[" + i + "] = " + sorted[i]);
The program does run but when i run it prints out the new array with a 2 at index zero and zeros for index 1-6.my objective is to have the new array print ar{7,5,2,8,4,9,6} array in order to be 2,3,4,5,6,7,8 There is some code I cannot change I have put which code i cant change Any help tips suggestions greatly appreciated.
asked 35 secs ago
Sort an array manually into a second array
Aucun commentaire:
Enregistrer un commentaire