Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.util.*;
  2. public class Test {
  3. public static void main(String [] args)
  4. {
  5. int[] myArray={70,60,26,9};
  6. for (int index1 = 0; index1 < 3 ; index1++) {
  7. for (int index2 = 0; index2 + index1 < 3 ; index2++){
  8. if ( myArray[index2] > myArray [index2+1]){
  9. /*this means we need to swap the two elements*/
  10.  
  11. byte tempValue = myArray[index2];
  12. /*store myArray[index2] in tempValue variable*/
  13.  
  14. myArray[index2] = myArray[index2+1];
  15. /*assign myArray[index2+1] value to myArray[index2]*/
  16.  
  17. myArray[index2+1] = tempValue;
  18. /*now assign myArray[index2]’s original value that was temporarily stored in tempValue to myArray[index2+1]*/
  19.  
  20. }/*end of if section*/
  21. }/*end of for with index2*/
  22. }/*end of for with index1*/
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement