Swapping elements of an array help please
ok i have this program where i have to prepare a ten element array using the following numbers 17 38 12 19 58 92 13 16 91 76
it says i have to read each cell of the array; find and print the largest number in the array and its location.then swap the largest number in the array with the first element in the array. then print the new array list
output is
largest number 92
position 6
92 38 12 19 58..
PLease help me if you do i will do something for you this is what i have so far
import javax.swing.JOptionPane;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class program56{
public static void main (String args[]){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int largest=0;
int c[10]={17,38,12,19,58,92,13,16,91,76}
System.out.println("Element" + "\t" + "value");
for(int x=0; x<c.length;x++)
{
System.out.print(+c[x]+" ");
if(c[x]>largest)
largest=c[x];
}
}
}
Re: Swapping elements of an array help please
i have to do a thing like an array{10,20,30,40,50,60,70,80,90}
and i have to swap the numbers 20 and 30 so it looks like
{10,30,20,40,50,60,70,80,90}
how do you do it?
Re: Swapping elements of an array help please
Please don't hijack and resurrect an old thread but instead re-ask your question in a new thread. Thank you for your cooperation in this.