I'm trying to switch the biggest and smallest element in this array using a for loop, however I can't seem to figure out how to do it. Can someone help me? That would be very much appreciated, thanks!
public void assign(int[]IntArray) {
int BiggestNumber = IntArray[0];
int SmallestNumber = IntArray[0];
for(int i = 0; i < IntArray.length; i++) {
if(IntArray[i] > BiggestNumber) {
BiggestNumber = IntArray[i];
} else if(IntArray[i] < SmallestNumber) {
SmallestNumber = IntArray[i];
}
}
BiggestNumber = IntArray[SmallestNumber];
System.out.println(BiggestNumber);
}