Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Test {
- public static void main(String [] args)
- {
- int[] myArray={70,60,26,9};
- for (int index1 = 0; index1 < 3 ; index1++) {
- for (int index2 = 0; index2 + index1 < 3 ; index2++){
- if ( myArray[index2] > myArray [index2+1]){
- /*this means we need to swap the two elements*/
- byte tempValue = myArray[index2];
- /*store myArray[index2] in tempValue variable*/
- myArray[index2] = myArray[index2+1];
- /*assign myArray[index2+1] value to myArray[index2]*/
- myArray[index2+1] = tempValue;
- /*now assign myArray[index2]’s original value that was temporarily stored in tempValue to myArray[index2+1]*/
- }/*end of if section*/
- }/*end of for with index2*/
- }/*end of for with index1*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement